1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.config;
18
19 import java.util.Objects;
20
21 import org.apache.logging.log4j.Level;
22 import org.apache.logging.log4j.core.config.plugins.Plugin;
23 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
24 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
25 import org.apache.logging.log4j.status.StatusLogger;
26
27
28
29
30 @Plugin(name = "CustomLevel", category = "Core", printObject = true)
31 public final class CustomLevelConfig {
32
33 private final String levelName;
34 private final int intLevel;
35
36 private CustomLevelConfig(final String levelName, final int intLevel) {
37 this.levelName = Objects.requireNonNull(levelName, "levelName is null");
38 this.intLevel = intLevel;
39 }
40
41
42
43
44
45
46
47
48
49 @PluginFactory
50 public static CustomLevelConfig createLevel(
51 @PluginAttribute("name") final String levelName,
52 @PluginAttribute("intLevel") final int intLevel) {
53
54
55 StatusLogger.getLogger().debug("Creating CustomLevel(name='{}', intValue={})", levelName, intLevel);
56 Level.forName(levelName, intLevel);
57 return new CustomLevelConfig(levelName, intLevel);
58 }
59
60
61
62
63
64
65 public String getLevelName() {
66 return levelName;
67 }
68
69
70
71
72
73
74
75 public int getIntLevel() {
76 return intLevel;
77 }
78
79 @Override
80 public int hashCode() {
81 return intLevel ^ levelName.hashCode();
82 }
83
84 @Override
85 public boolean equals(final Object object) {
86 if (this == object) {
87 return true;
88 }
89 if (!(object instanceof CustomLevelConfig)) {
90 return false;
91 }
92 final CustomLevelConfig other = (CustomLevelConfig) object;
93 return this.intLevel == other.intLevel && this.levelName.equals(other.levelName);
94 }
95
96 @Override
97 public String toString() {
98 return "CustomLevel[name=" + levelName + ", intLevel=" + intLevel + "]";
99 }
100 }