SimpleLogger.java

1
package fi.eis.libraries.di.logger;
2
3
import java.io.PrintStream;
4
import java.util.Date;
5
import java.util.logging.Level;
6
import java.util.logging.Logger;
7
8
/**
9
 * Simple logger that can delegate to java.util.logging or System.out.
10
 *
11
 * By default, JUL is used, but it can be overridden with a property.
12
 *
13
 * JUL support is due to fact that it's available in all java environments without additional dependencies,
14
 * and with jul bridge, can be redirected to wherever if needed.
15
 */
16
public class SimpleLogger {
17
18
    public static final String PROPERTY_NAME_USE_SYSTEM_OUT_LOGGING = "minimal-di.logging.systemout";
19
    public enum LoggingBackend {
20
        USE_SYSTEM_OUT,
21
        USE_JUL_LOGGING
22
    }
23 1 1. <init> : Removed assignment to member variable logLevel → KILLED
    private volatile LogLevel logLevel = LogLevel.NONE;
24
25
    private final String className;
26
    private final Logger logger;
27
28 1 1. <init> : Removed assignment to member variable printStream → KILLED
    private transient PrintStream printStream = System.out;
29
30
    private final LoggingBackend loggingBackend;
31
32
    public SimpleLogger(Class<?> targetClass) {
33
        this(targetClass,
34 6 1. <init> : removed conditional - replaced equality check with true → KILLED
2. <init> : removed call to java/lang/System::getProperty → KILLED
3. <init> : negated conditional → KILLED
4. <init> : replaced call to java/lang/System::getProperty with argument → KILLED
5. <init> : removed call to java/lang/Boolean::parseBoolean → KILLED
6. <init> : removed conditional - replaced equality check with false → KILLED
                Boolean.parseBoolean(System.getProperty(PROPERTY_NAME_USE_SYSTEM_OUT_LOGGING, "false"))
35
                        ? LoggingBackend.USE_SYSTEM_OUT : LoggingBackend.USE_JUL_LOGGING);
36
    }
37
    public SimpleLogger(Class<?> targetClass, LoggingBackend loggingBackend) {
38 2 1. <init> : Removed assignment to member variable className → SURVIVED
2. <init> : removed call to java/lang/Class::getName → SURVIVED
        this.className = targetClass.getName();
39 1 1. <init> : Removed assignment to member variable loggingBackend → KILLED
        this.loggingBackend = loggingBackend;
40
        
41 3 1. <init> : removed conditional - replaced equality check with true → SURVIVED
2. <init> : negated conditional → KILLED
3. <init> : removed conditional - replaced equality check with false → KILLED
        if (loggingBackend == LoggingBackend.USE_JUL_LOGGING) {
42 3 1. <init> : Removed assignment to member variable logger → KILLED
2. <init> : removed call to java/util/logging/Logger::getLogger → KILLED
3. <init> : removed call to java/lang/Class::getSimpleName → KILLED
            this.logger = Logger.getLogger(targetClass.getSimpleName());
43
        } else {
44
            this.logger = null;
45
        }
46
    }
47
    public void setLogLevel(LogLevel value) {
48 1 1. setLogLevel : Removed assignment to member variable logLevel → KILLED
        this.logLevel = value;
49
    }
50
    public boolean isDebugEnabled() {
51 9 1. isDebugEnabled : replaced boolean return with true for fi/eis/libraries/di/logger/SimpleLogger::isDebugEnabled → KILLED
2. isDebugEnabled : removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED
3. isDebugEnabled : removed conditional - replaced comparison check with false → KILLED
4. isDebugEnabled : removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED
5. isDebugEnabled : removed conditional - replaced comparison check with true → KILLED
6. isDebugEnabled : changed conditional boundary → KILLED
7. isDebugEnabled : negated conditional → KILLED
8. isDebugEnabled : Substituted 1 with 0 → KILLED
9. isDebugEnabled : Substituted 0 with 1 → KILLED
        return this.logLevel.ordinal() >= LogLevel.DEBUG.ordinal();
52
    }
53
    public boolean isErrorEnabled() {
54 9 1. isErrorEnabled : Substituted 0 with 1 → KILLED
2. isErrorEnabled : Substituted 1 with 0 → KILLED
3. isErrorEnabled : removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED
4. isErrorEnabled : replaced boolean return with true for fi/eis/libraries/di/logger/SimpleLogger::isErrorEnabled → KILLED
5. isErrorEnabled : removed conditional - replaced comparison check with false → KILLED
6. isErrorEnabled : removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED
7. isErrorEnabled : changed conditional boundary → KILLED
8. isErrorEnabled : negated conditional → KILLED
9. isErrorEnabled : removed conditional - replaced comparison check with true → KILLED
        return this.logLevel.ordinal() >= LogLevel.ERROR.ordinal();
55
    }
56
    
57
    public void debug(String message) {
58
        if (!this.isDebugEnabled()) {
59
            return;
60
        }
61 3 1. debug : removed conditional - replaced equality check with true → KILLED
2. debug : removed conditional - replaced equality check with false → KILLED
3. debug : negated conditional → KILLED
        if (loggingBackend == LoggingBackend.USE_SYSTEM_OUT) {
62 7 1. debug : Substituted 3 with 4 → SURVIVED
2. debug : removed call to java/util/Date::<init> → SURVIVED
3. debug : Substituted 1 with 0 → SURVIVED
4. debug : Substituted 0 with 1 → SURVIVED
5. debug : replaced call to java/io/PrintStream::printf with receiver → KILLED
6. debug : Substituted 2 with 3 → KILLED
7. debug : removed call to java/io/PrintStream::printf → KILLED
            printStream.printf("%s DEBUG %s: %s%n",
63
                    new Date(), className, message);
64
        } else {
65 1 1. debug : removed call to java/util/logging/Logger::log → KILLED
            this.logger.log(Level.FINE, message);
66
        }
67
    }
68
    public void debug(String message, Object... parameters) {
69
        if (this.isDebugEnabled()) {
70
            debug(String.format(message, parameters));
71
        }
72
    }
73
    public void error(String message) {
74
        if (!this.isErrorEnabled()) {
75
            return;
76
        }
77 3 1. error : removed conditional - replaced equality check with false → KILLED
2. error : negated conditional → KILLED
3. error : removed conditional - replaced equality check with true → KILLED
        if (loggingBackend == LoggingBackend.USE_SYSTEM_OUT) {
78 7 1. error : Substituted 0 with 1 → SURVIVED
2. error : Substituted 3 with 4 → SURVIVED
3. error : removed call to java/util/Date::<init> → SURVIVED
4. error : Substituted 1 with 0 → SURVIVED
5. error : replaced call to java/io/PrintStream::printf with receiver → KILLED
6. error : removed call to java/io/PrintStream::printf → KILLED
7. error : Substituted 2 with 3 → KILLED
            printStream.printf("%s ERROR %s: %s%n",
79
                    new Date(), className, message);
80
        } else {
81 1 1. error : removed call to java/util/logging/Logger::log → KILLED
            this.logger.log(Level.SEVERE, message);
82
        }
83
    }
84
    public void error(String message, Object... parameters) {
85
        if (this.isErrorEnabled()) {
86
            error(String.format(message, parameters));
87
        }
88
    }
89
90
    /** package-private to facilitate testing - we don't need to set this from everywhere */
91
    void setPrintOut(PrintStream stream) {
92 1 1. setPrintOut : Removed assignment to member variable printStream → KILLED
        this.printStream = stream;
93
    }
94
}

Mutations

23

1.1
Location : <init>
Killed by : fi.eis.libraries.di.test.moduleconfig.DIInheritanceTest.testDi(fi.eis.libraries.di.test.moduleconfig.DIInheritanceTest)
Removed assignment to member variable logLevel → KILLED

28

1.1
Location : <init>
Killed by : fi.eis.libraries.di.test.moduleconfig.DIConstructorTest.testDiWithLoggingEnabled(fi.eis.libraries.di.test.moduleconfig.DIConstructorTest)
Removed assignment to member variable printStream → KILLED

34

1.1
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed conditional - replaced equality check with true → KILLED

2.2
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed call to java/lang/System::getProperty → KILLED

3.3
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
negated conditional → KILLED

4.4
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
replaced call to java/lang/System::getProperty with argument → KILLED

5.5
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed call to java/lang/Boolean::parseBoolean → KILLED

6.6
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed conditional - replaced equality check with false → KILLED

38

1.1
Location : <init>
Killed by : none
Removed assignment to member variable className → SURVIVED
Covering tests

2.2
Location : <init>
Killed by : none
removed call to java/lang/Class::getName → SURVIVED Covering tests

39

1.1
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
Removed assignment to member variable loggingBackend → KILLED

41

1.1
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
negated conditional → KILLED

2.2
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed conditional - replaced equality check with false → KILLED

3.3
Location : <init>
Killed by : none
removed conditional - replaced equality check with true → SURVIVED
Covering tests

42

1.1
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
Removed assignment to member variable logger → KILLED

2.2
Location : <init>
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed call to java/util/logging/Logger::getLogger → KILLED

3.3
Location : <init>
Killed by : fi.eis.libraries.di.test.deploymentunit.DIClassScanningJarLoadingTest.testDiWithNonExistingFile(fi.eis.libraries.di.test.deploymentunit.DIClassScanningJarLoadingTest)
removed call to java/lang/Class::getSimpleName → KILLED

48

1.1
Location : setLogLevel
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
Removed assignment to member variable logLevel → KILLED

51

1.1
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
replaced boolean return with true for fi/eis/libraries/di/logger/SimpleLogger::isDebugEnabled → KILLED

2.2
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED

3.3
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed conditional - replaced comparison check with false → KILLED

4.4
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED

5.5
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed conditional - replaced comparison check with true → KILLED

6.6
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
changed conditional boundary → KILLED

7.7
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
negated conditional → KILLED

8.8
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
Substituted 1 with 0 → KILLED

9.9
Location : isDebugEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
Substituted 0 with 1 → KILLED

54

1.1
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testNoneLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
Substituted 0 with 1 → KILLED

2.2
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
Substituted 1 with 0 → KILLED

3.3
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED

4.4
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testNoneLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
replaced boolean return with true for fi/eis/libraries/di/logger/SimpleLogger::isErrorEnabled → KILLED

5.5
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed conditional - replaced comparison check with false → KILLED

6.6
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testNoneLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed call to fi/eis/libraries/di/logger/LogLevel::ordinal → KILLED

7.7
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
changed conditional boundary → KILLED

8.8
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
negated conditional → KILLED

9.9
Location : isErrorEnabled
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testNoneLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed conditional - replaced comparison check with true → KILLED

61

1.1
Location : debug
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testDebugLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed conditional - replaced equality check with true → KILLED

2.2
Location : debug
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed conditional - replaced equality check with false → KILLED

3.3
Location : debug
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
negated conditional → KILLED

62

1.1
Location : debug
Killed by : none
Substituted 3 with 4 → SURVIVED
Covering tests

2.2
Location : debug
Killed by : none
removed call to java/util/Date::<init> → SURVIVED Covering tests

3.3
Location : debug
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
replaced call to java/io/PrintStream::printf with receiver → KILLED

4.4
Location : debug
Killed by : none
Substituted 1 with 0 → SURVIVED Covering tests

5.5
Location : debug
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
Substituted 2 with 3 → KILLED

6.6
Location : debug
Killed by : none
Substituted 0 with 1 → SURVIVED Covering tests

7.7
Location : debug
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed call to java/io/PrintStream::printf → KILLED

65

1.1
Location : debug
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testDebugLevelDebugLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed call to java/util/logging/Logger::log → KILLED

77

1.1
Location : error
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed conditional - replaced equality check with false → KILLED

2.2
Location : error
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
negated conditional → KILLED

3.3
Location : error
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed conditional - replaced equality check with true → KILLED

78

1.1
Location : error
Killed by : none
Substituted 0 with 1 → SURVIVED
Covering tests

2.2
Location : error
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
replaced call to java/io/PrintStream::printf with receiver → KILLED

3.3
Location : error
Killed by : none
Substituted 3 with 4 → SURVIVED Covering tests

4.4
Location : error
Killed by : none
removed call to java/util/Date::<init> → SURVIVED Covering tests

5.5
Location : error
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
removed call to java/io/PrintStream::printf → KILLED

6.6
Location : error
Killed by : none
Substituted 1 with 0 → SURVIVED Covering tests

7.7
Location : error
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
Substituted 2 with 3 → KILLED

81

1.1
Location : error
Killed by : fi.eis.libraries.di.logger.SimpleJULLoggerTest.testErrorLevelErrorLogging(fi.eis.libraries.di.logger.SimpleJULLoggerTest)
removed call to java/util/logging/Logger::log → KILLED

92

1.1
Location : setPrintOut
Killed by : fi.eis.libraries.di.logger.SimpleSystemOutLoggerTest
Removed assignment to member variable printStream → KILLED

Active mutators

Tests examined


Report generated by PIT 1.25.4 support