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