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 |
|
42 |
1.1 |
|
44 |
1.1 |
|
50 |
1.1 |
|
56 |
1.1 2.2 |
|
70 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |