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.unexceptional.Exceptional.swallow; | |
22 | import static io.earcam.utilitarian.log.slf4j.Constants.SYSTEM_PREFIX; | |
23 | ||
24 | /** | |
25 | * <p> | |
26 | * Programmatic configuration for SLF4J logging | |
27 | * </p> | |
28 | * | |
29 | * | |
30 | * http://docs.jboss.org/hibernate/orm/4.3/topical/html/logging/Logging.html | |
31 | * https://www.eclipse.org/jetty/documentation/9.3.x/configuring-logging.html | |
32 | * http://docs.hazelcast.org/docs/3.5/manual/html/logging.html | |
33 | * http://cxf.apache.org/docs/general-cxf-logging.html | |
34 | * https://wiki.eclipse.org/EclipseLink/Development/296391 | |
35 | */ | |
36 | public final class Logging implements LoggingBuilder, LoggerName { | |
37 | ||
38 | private static final String CACHE_OUTPUT_STREAM_STRING_KEY = SYSTEM_PREFIX + "cacheOutputStream"; | |
39 | ||
40 | private static final String LOGGER_PROPERTY_CXF = "org.apache.cxf.Logger"; | |
41 | private static final String LOGGER_IMP_CXF = "org.apache.cxf.common.logging.Slf4jLogger"; | |
42 | ||
43 | private static final String LOGGER_PROPERTY_JETTY = "org.eclipse.jetty.util.log.class"; | |
44 | private static final String LOGGER_IMP_JETTY = "org.eclipse.jetty.util.log.Slf4jLog"; | |
45 | ||
46 | private static final String LOGGER_PROPERTY_ECLIPSELINK = "eclipselink.logging.logger"; | |
47 | private static final String LOGGER_IMP_ECLIPSELINK = "org.eclipse.persistence.logging.slf4j.SLF4JLogger"; | |
48 | ||
49 | private static final String SLF_4_YAY = "slf4j"; | |
50 | ||
51 | private static final String LOGGER_PROPERTY_HAZELCAST = "hazelcast.logging.type"; | |
52 | private static final String LOGGER_PROPERTY_JBOSS = "org.jboss.logging.provider"; | |
53 | ||
54 | ||
55 | private Logging() | |
56 | {} | |
57 | ||
58 | ||
59 | public static LoggingBuilder logging() | |
60 | { | |
61 |
1
1. logging : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Logging::logging to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new Logging(); |
62 | } | |
63 | ||
64 | ||
65 | @Override | |
66 | public LogAtLevel log(String loggerName) | |
67 | { | |
68 |
1
1. log : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Logging::log to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return Levels.create().log(loggerName); |
69 | } | |
70 | ||
71 | ||
72 | @Override | |
73 | public LoggingBuilder defaultLevel(Level defaultLevel) | |
74 | { | |
75 | Levels.createWithDefault(defaultLevel); | |
76 |
1
1. defaultLevel : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Logging::defaultLevel to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
77 | } | |
78 | ||
79 | ||
80 | @Override | |
81 | public LoggingBuilder configureFrameworks() | |
82 | { | |
83 | System.setProperty(CACHE_OUTPUT_STREAM_STRING_KEY, Boolean.toString(false)); | |
84 | ||
85 | System.setProperty(LOGGER_PROPERTY_JBOSS, SLF_4_YAY); | |
86 | System.setProperty(LOGGER_PROPERTY_HAZELCAST, SLF_4_YAY); | |
87 | ||
88 |
1
1. configureFrameworks : removed call to io/earcam/utilitarian/log/slf4j/Logging::setPropertyIfClassPresent → SURVIVED |
setPropertyIfClassPresent(LOGGER_PROPERTY_JETTY, LOGGER_IMP_JETTY); |
89 |
1
1. configureFrameworks : removed call to io/earcam/utilitarian/log/slf4j/Logging::setPropertyIfClassPresent → SURVIVED |
setPropertyIfClassPresent(LOGGER_PROPERTY_ECLIPSELINK, LOGGER_IMP_ECLIPSELINK); |
90 |
1
1. configureFrameworks : removed call to io/earcam/utilitarian/log/slf4j/Logging::setPropertyIfClassPresent → SURVIVED |
setPropertyIfClassPresent(LOGGER_PROPERTY_CXF, LOGGER_IMP_CXF); |
91 | ||
92 |
1
1. configureFrameworks : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Logging::configureFrameworks to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
93 | } | |
94 | ||
95 | ||
96 | private static void setPropertyIfClassPresent(String property, String implementation) | |
97 | { | |
98 | try { | |
99 | Logging.class.getClassLoader().loadClass(implementation); | |
100 | System.setProperty(property, implementation); | |
101 | } catch(ClassNotFoundException e) { | |
102 |
1
1. setPropertyIfClassPresent : removed call to io/earcam/unexceptional/Exceptional::swallow → SURVIVED |
swallow(e); |
103 | } | |
104 | } | |
105 | ||
106 | ||
107 | /** | |
108 | * If you're reliant on log output for test assertions then something is probably wrong. | |
109 | * That said, cases (such as refactoring age-old legacy code) do exist | |
110 | * | |
111 | * @param runnable | |
112 | * @return the captured log output | |
113 | */ | |
114 | public static String capture(LogCapturable runnable) | |
115 | { | |
116 |
1
1. capture : mutated return of Object value for io/earcam/utilitarian/log/slf4j/Logging::capture to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return LoggingCapture.capture(runnable); |
117 | } | |
118 | } | |
Mutations | ||
61 |
1.1 |
|
68 |
1.1 |
|
76 |
1.1 |
|
88 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
92 |
1.1 |
|
102 |
1.1 |
|
116 |
1.1 |