-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.java
More file actions
38 lines (32 loc) · 1.02 KB
/
Copy pathLogger.java
File metadata and controls
38 lines (32 loc) · 1.02 KB
1
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
27
28
29
30
31
32
33
34
35
36
37
38
package com.catherine.chain_of_responsibility;
/**
* 打印log时,权重最高的{@code ERROR}在较次的权重过滤器中都能打印,反之权重最低的{@code DEBUG},在其它权重过滤器时都不会被打印。
* <br>
* 先设置logger链,在用的时候一律执行ErrorLogger的实例,呼叫logMessage时就会带入log级别,具体详见{@link #com.catherine.Main.testChainOfResponsibility()}
*
* @author Catherine
*
*/
public abstract class Logger {
public final static int DEBUG = 0;
public final static int WARNING = 1;
public final static int ERROR = 2;
protected Logger nextLogger;
protected int level;
public void setNextLogger(Logger nextLogger) {
this.nextLogger = nextLogger;
}
/**
* 利用迭代来打印较小权重的log
*
* @param level
* @param message
*/
public void logMessage(int level, String message) {
if (this.level <= level)
write(message);
if (nextLogger != null)
nextLogger.logMessage(level, message);
}
public abstract void write(String message);
}