1 package org.codehaus.plexus.logging;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public abstract class AbstractLogger implements Logger {
27 private int threshold;
28
29 private String name;
30
31 public AbstractLogger(int threshold, String name) {
32 if (!isValidThreshold(threshold)) {
33 throw new IllegalArgumentException("Threshold " + threshold + " is not valid");
34 }
35
36 this.threshold = threshold;
37 this.name = name;
38 }
39
40 public int getThreshold() {
41 return threshold;
42 }
43
44 public void setThreshold(int threshold) {
45 this.threshold = threshold;
46 }
47
48 public String getName() {
49 return name;
50 }
51
52 public void debug(String message) {
53 debug(message, null);
54 }
55
56 public boolean isDebugEnabled() {
57 return threshold <= LEVEL_DEBUG;
58 }
59
60 public void info(String message) {
61 info(message, null);
62 }
63
64 public boolean isInfoEnabled() {
65 return threshold <= LEVEL_INFO;
66 }
67
68 public void warn(String message) {
69 warn(message, null);
70 }
71
72 public boolean isWarnEnabled() {
73 return threshold <= LEVEL_WARN;
74 }
75
76 public void error(String message) {
77 error(message, null);
78 }
79
80 public boolean isErrorEnabled() {
81 return threshold <= LEVEL_ERROR;
82 }
83
84 public void fatalError(String message) {
85 fatalError(message, null);
86 }
87
88 public boolean isFatalErrorEnabled() {
89 return threshold <= LEVEL_FATAL;
90 }
91
92 protected boolean isValidThreshold(int threshold) {
93 if (threshold == LEVEL_DEBUG) {
94 return true;
95 }
96 if (threshold == LEVEL_INFO) {
97 return true;
98 }
99 if (threshold == LEVEL_WARN) {
100 return true;
101 }
102 if (threshold == LEVEL_ERROR) {
103 return true;
104 }
105 if (threshold == LEVEL_FATAL) {
106 return true;
107 }
108 if (threshold == LEVEL_DISABLED) {
109 return true;
110 }
111
112 return false;
113 }
114 }