1 package org.kuali.common.util.log.log4j.model;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import javax.xml.bind.annotation.XmlAttribute;
8 import javax.xml.bind.annotation.XmlElement;
9 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
10
11 import org.kuali.common.util.Assert;
12 import org.kuali.common.util.CollectionUtils;
13 import org.kuali.common.util.nullify.NullUtils;
14 import org.kuali.common.util.xml.jaxb.adapter.OmitNoneStringAdapter;
15 import org.kuali.common.util.xml.jaxb.adapter.OmitTrueAdapter;
16
17 public class Logger {
18
19 public static final List<Logger> EMPTY = Collections.<Logger> emptyList();
20 public static final boolean DEFAULT_ADDITIVITY = true;
21 public static final Logger DEFAULT = new Logger();
22
23 @XmlAttribute
24 @XmlJavaTypeAdapter(OmitNoneStringAdapter.class)
25 private final String name;
26
27 @XmlElement(name = "appender-ref")
28 private final List<AppenderRef> references;
29
30 @XmlElement
31 private final Level level;
32
33 @XmlAttribute
34 @XmlJavaTypeAdapter(OmitTrueAdapter.class)
35 private final Boolean additivity;
36
37 private Logger() {
38 this(NullUtils.NONE, AppenderRef.EMPTY, Level.DEFAULT);
39 }
40
41 public Logger(String name, Level level) {
42 this(name, AppenderRef.EMPTY, level, DEFAULT_ADDITIVITY);
43 }
44
45 public Logger(String name, List<AppenderRef> references) {
46 this(name, references, Level.DEFAULT, DEFAULT_ADDITIVITY);
47 }
48
49 public Logger(String name, List<AppenderRef> references, Level level) {
50 this(name, references, level, DEFAULT_ADDITIVITY);
51 }
52
53 public Logger(String name, List<AppenderRef> references, Level level, boolean additivity) {
54 Assert.noBlanks(name);
55 Assert.noNulls(references, level);
56 this.name = name;
57 this.references = new ArrayList<AppenderRef>(references);
58 this.level = level;
59 this.additivity = additivity;
60 }
61
62 public List<AppenderRef> getReferences() {
63 return Collections.unmodifiableList(references);
64 }
65
66 public boolean getAdditivity() {
67 return additivity;
68 }
69
70 public String getName() {
71 return name;
72 }
73
74 public Level getLevel() {
75 return level;
76 }
77
78 public static boolean isThresholdNull(Logger logger) {
79 return Threshold.NULL.equals(logger.getLevel().getValue());
80 }
81
82 public static Logger getRootLogger(AppenderRef reference, Level level) {
83 return getRootLogger(CollectionUtils.singletonList(reference), level);
84 }
85
86 public static Logger getRootLogger(List<AppenderRef> references, Level level) {
87 return new Logger(NullUtils.NONE, references, level);
88 }
89 }