Levels.java

1
/*-
2
 * #%L
3
 * io.earcam.utilitarian.log.slf4j
4
 * %%
5
 * Copyright (C) 2017 earcam
6
 * %%
7
 * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8
 *
9
 * You <b>must</b> choose to accept, in full - any individual or combination of
10
 * the following licenses:
11
 * <ul>
12
 * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13
 * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14
 * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15
 * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16
 * </ul>
17
 * #L%
18
 */
19
package io.earcam.utilitarian.log.slf4j;
20
21
import static io.earcam.utilitarian.log.slf4j.Constants.*;
22
23
final class Levels implements LoggingBuilder.LogAtLevel, LoggerName {
24
25
	private String lastLoggerName;
26
27
28
	private Levels()
29
	{}
30
31
32
	/**
33
	 * Will not overwrite the {@value SimpleLogger#DEFAULT_LOG_LEVEL_KEY} system property if present
34
	 * (to allow external control from, e.g. build properties
35
	 *
36
	 * @param level
37
	 * @return
38
	 */
39
	static final LoggerName createWithDefault(Level level)
40
	{
41 1 1. createWithDefault : negated conditional → SURVIVED
		if(isNullOrEmpty(System.getProperty(DEFAULT_LOG_LEVEL_KEY))) {
42 1 1. createWithDefault : removed call to io/earcam/utilitarian/log/slf4j/Levels::set → SURVIVED
			set(DEFAULT_LOG_LEVEL_KEY, level);
43
		}
44 1 1. createWithDefault : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::createWithDefault to ( if (x != null) null else throw new RuntimeException ) → SURVIVED
		return create();
45
	}
46
47
48
	static final LoggerName create()
49
	{
50 1 1. create : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::create to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return new Levels();
51
	}
52
53
54
	private static boolean isNullOrEmpty(String property)
55
	{
56 2 1. isNullOrEmpty : negated conditional → SURVIVED
2. isNullOrEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED
		return property == null;
57
	}
58
59
60
	private static void set(String loggerCategory, Level level)
61
	{
62
		System.setProperty(loggerCategory, level.toString());
63
	}
64
65
66
	@Override
67
	public LoggingBuilder.LogAtLevel log(String loggerName)
68
	{
69
		lastLoggerName = loggerName;
70 1 1. log : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::log to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return this;
71
	}
72
73
74
	/**
75
	 * Can also be used to during execution to change levels
76
	 */
77
	@Override
78
	public LoggerName at(Level level)
79
	{
80 1 1. at : removed call to io/earcam/utilitarian/log/slf4j/Levels::set → SURVIVED
		set(LOG_KEY_PREFIX + lastLoggerName, level);
81 1 1. at : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::at to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return this;
82
	}
83
}

Mutations

41

1.1
Location : createWithDefault
Killed by : none
negated conditional → SURVIVED

42

1.1
Location : createWithDefault
Killed by : none
removed call to io/earcam/utilitarian/log/slf4j/Levels::set → SURVIVED

44

1.1
Location : createWithDefault
Killed by : none
mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::createWithDefault to ( if (x != null) null else throw new RuntimeException ) → SURVIVED

50

1.1
Location : create
Killed by : io.earcam.utilitarian.log.slf4j.LoggingTest.basicCaptureOverStdOut()
mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::create to ( if (x != null) null else throw new RuntimeException ) → KILLED

56

1.1
Location : isNullOrEmpty
Killed by : none
negated conditional → SURVIVED

2.2
Location : isNullOrEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED

70

1.1
Location : log
Killed by : io.earcam.utilitarian.log.slf4j.LoggingTest.basicCaptureOverStdOut()
mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::log to ( if (x != null) null else throw new RuntimeException ) → KILLED

80

1.1
Location : at
Killed by : none
removed call to io/earcam/utilitarian/log/slf4j/Levels::set → SURVIVED

81

1.1
Location : at
Killed by : io.earcam.utilitarian.log.slf4j.LoggingTest.individualLogLevelsAreHonoured()
mutated return of Object value for io/earcam/utilitarian/log/slf4j/Levels::at to ( if (x != null) null else throw new RuntimeException ) → KILLED

Active mutators

Tests examined


Report generated by PIT 1.4.3