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