LogbackLogger.java

1
package org.europa.together.application;
2
3
import java.io.File;
4
import java.util.Arrays;
5
import org.europa.together.business.Logger;
6
import org.europa.together.domain.LogLevel;
7
import org.europa.together.utils.Constraints;
8
import org.slf4j.LoggerFactory;
9
10
/**
11
 * Implementation of the Logger as Wrapper for SLF4j and logback Framework.
12
 */
13
//@Repository
14
public class LogbackLogger implements Logger {
15
16
    private static final long serialVersionUID = 1L;
17
    private final String configurationFile = Constraints.SYSTEM_APP_DIR + "/logback.xml";
18
    private Class<?> instance = null;
19
    private org.slf4j.Logger logger = null;
20
21
    /**
22
     * Create an instance of the logging class. THe configuration file will be
23
     * searched in the Directory, where the application is running.<br>
24
     *
25
     * see: org/europa/together/configuration/logback.xml If is no configuration
26
     * present at this position, the logger use the default configuration in the
27
     * classpath, with the console appender.
28
     *
29
     * @param instance The instance of the logged CLASS
30
     */
31
    public LogbackLogger(final Class<?> instance) {
32
        this.instance = instance;
33
34
        //FALLBACK
35 1 1. <init> : negated conditional → SURVIVED
        if (new File(configurationFile).exists()) {
36
            System.setProperty("configurationFile", configurationFile);
37
        }
38
    }
39
40
    @Override
41
    public LogLevel log(final String message, final LogLevel level) {
42 1 1. log : removed call to org/europa/together/application/LogbackLogger::instanceLogger → KILLED
        instanceLogger();
43
        switch (level) {
44
            case TRACE:
45
                logger.trace(message);
46
                break;
47
            case DEBUG:
48
                logger.debug(message);
49
                break;
50
            case INFO:
51
                logger.info(message);
52
                break;
53
            case WARN:
54
                logger.warn(message);
55
                break;
56
            default:
57
                logger.error(message);
58
                break;
59
        }
60 1 1. log : replaced return value with null for org/europa/together/application/LogbackLogger::log → KILLED
        return level;
61
    }
62
63
    public String getLoggerName() {
64
        return logger.getName();
65
    }
66
67
    @Override
68
    public LogLevel getConfiguredLogLevel() {
69 1 1. getConfiguredLogLevel : removed call to org/europa/together/application/LogbackLogger::instanceLogger → SURVIVED
        instanceLogger();
70
        LogLevel level = null;
71
        if (logger.isErrorEnabled()) {
72
            level = LogLevel.ERROR;
73
        }
74
        if (logger.isWarnEnabled()) {
75
            level = LogLevel.WARN;
76
        }
77
        if (logger.isInfoEnabled()) {
78
            level = LogLevel.INFO;
79
        }
80
        if (logger.isDebugEnabled()) {
81
            level = LogLevel.DEBUG;
82
        }
83
        if (logger.isTraceEnabled()) {
84
            level = LogLevel.TRACE;
85
        }
86 1 1. getConfiguredLogLevel : replaced return value with null for org/europa/together/application/LogbackLogger::getConfiguredLogLevel → KILLED
        return level;
87
    }
88
89
    @Override
90
    public String catchException(final Exception ex) {
91 1 1. catchException : removed call to org/europa/together/application/LogbackLogger::instanceLogger → KILLED
        instanceLogger();
92
        String exceptionType = ex.getClass().getSimpleName();
93
        logger.error(exceptionType + ": " + ex.getMessage());
94 1 1. catchException : negated conditional → SURVIVED
        if (exceptionType.equals("NullPointerException")) {
95
            logger.error(Arrays.toString(ex.getStackTrace()));
96
        }
97 1 1. catchException : replaced return value with "" for org/europa/together/application/LogbackLogger::catchException → KILLED
        return ex.getMessage();
98
    }
99
100
    private void instanceLogger() {
101 1 1. instanceLogger : negated conditional → KILLED
        if (logger == null) {
102
            logger = LoggerFactory.getILoggerFactory().getLogger(instance.getName());
103
        }
104
    }
105
}

Mutations

35

1.1
Location : <init>
Killed by : none
negated conditional → SURVIVED
Covering tests

42

1.1
Location : log
Killed by : org.europa.together.application.LogbackLoggerTest.[engine:junit-jupiter]/[class:org.europa.together.application.LogbackLoggerTest]/[method:logDebug()]
removed call to org/europa/together/application/LogbackLogger::instanceLogger → KILLED

60

1.1
Location : log
Killed by : org.europa.together.application.LogbackLoggerTest.[engine:junit-jupiter]/[class:org.europa.together.application.LogbackLoggerTest]/[method:logDebug()]
replaced return value with null for org/europa/together/application/LogbackLogger::log → KILLED

69

1.1
Location : getConfiguredLogLevel
Killed by : none
removed call to org/europa/together/application/LogbackLogger::instanceLogger → SURVIVED
Covering tests

86

1.1
Location : getConfiguredLogLevel
Killed by : org.europa.together.application.LogbackLoggerTest.[engine:junit-jupiter]/[class:org.europa.together.application.LogbackLoggerTest]/[method:getLogLevel()]
replaced return value with null for org/europa/together/application/LogbackLogger::getConfiguredLogLevel → KILLED

91

1.1
Location : catchException
Killed by : org.europa.together.application.LogbackLoggerTest.[engine:junit-jupiter]/[class:org.europa.together.application.LogbackLoggerTest]/[method:catchNullpointerException()]
removed call to org/europa/together/application/LogbackLogger::instanceLogger → KILLED

94

1.1
Location : catchException
Killed by : none
negated conditional → SURVIVED
Covering tests

97

1.1
Location : catchException
Killed by : org.europa.together.application.LogbackLoggerTest.[engine:junit-jupiter]/[class:org.europa.together.application.LogbackLoggerTest]/[method:catchNullpointerException()]
replaced return value with "" for org/europa/together/application/LogbackLogger::catchException → KILLED

101

1.1
Location : instanceLogger
Killed by : org.europa.together.application.LogbackLoggerTest.[engine:junit-jupiter]/[class:org.europa.together.application.LogbackLoggerTest]/[method:logDebug()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0