1 | |
package liquibase.logging.core; |
2 | |
|
3 | |
import liquibase.logging.LogLevel; |
4 | |
import liquibase.util.StringUtils; |
5 | |
|
6 | |
import java.text.DateFormat; |
7 | |
import java.util.Date; |
8 | |
|
9 | |
public class DefaultLogger extends AbstractLogger { |
10 | |
|
11 | 16 | private String name = "liquibase"; |
12 | |
|
13 | 16 | public DefaultLogger() { |
14 | 16 | String passedLevel = System.getProperty("liquibase.defaultlogger.level"); |
15 | 16 | if (passedLevel == null) { |
16 | 0 | setLogLevel(LogLevel.INFO); |
17 | |
} else { |
18 | 16 | setLogLevel(passedLevel); |
19 | |
} |
20 | 16 | } |
21 | |
|
22 | |
public int getPriority() { |
23 | 0 | return 1; |
24 | |
} |
25 | |
|
26 | |
public void setName(String name) { |
27 | 1 | this.name = name; |
28 | 1 | } |
29 | |
|
30 | |
public void setLogLevel(String logLevel, String logFile) { |
31 | 0 | setLogLevel(logLevel); |
32 | 0 | } |
33 | |
|
34 | |
public void severe(String message) { |
35 | 1 | if (getLogLevel().compareTo(LogLevel.SEVERE) <= 0) { |
36 | 1 | print(LogLevel.SEVERE, message); |
37 | |
} |
38 | 1 | } |
39 | |
|
40 | |
protected void print(LogLevel logLevel, String message) { |
41 | 29 | if (StringUtils.trimToNull(message) == null) { |
42 | 0 | return; |
43 | |
} |
44 | |
|
45 | 29 | System.err.println(logLevel + " " |
46 | |
+ DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()) + ":" + name |
47 | |
+ ": " + message); |
48 | 29 | } |
49 | |
|
50 | |
public void severe(String message, Throwable e) { |
51 | 0 | if (getLogLevel().compareTo(LogLevel.SEVERE) <= 0) { |
52 | 0 | print(LogLevel.SEVERE, message); |
53 | 0 | e.printStackTrace(); |
54 | |
} |
55 | 0 | } |
56 | |
|
57 | |
public void warning(String message) { |
58 | 2 | if (getLogLevel().compareTo(LogLevel.WARNING) <= 0) { |
59 | 2 | print(LogLevel.WARNING, message); |
60 | |
} |
61 | 2 | } |
62 | |
|
63 | |
public void warning(String message, Throwable e) { |
64 | 0 | if (getLogLevel().compareTo(LogLevel.WARNING) <= 0) { |
65 | 0 | print(LogLevel.WARNING, message); |
66 | 0 | e.printStackTrace(); |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
public void info(String message) { |
71 | 27 | if (getLogLevel().compareTo(LogLevel.INFO) <= 0) { |
72 | 26 | print(LogLevel.INFO, message); |
73 | |
} |
74 | 27 | } |
75 | |
|
76 | |
public void info(String message, Throwable e) { |
77 | 0 | if (getLogLevel().compareTo(LogLevel.INFO) <= 0) { |
78 | 0 | print(LogLevel.INFO, message); |
79 | 0 | e.printStackTrace(); |
80 | |
} |
81 | 0 | } |
82 | |
|
83 | |
public void debug(String message) { |
84 | 16765 | if (getLogLevel().compareTo(LogLevel.DEBUG) <= 0) { |
85 | 0 | print(LogLevel.DEBUG, message); |
86 | |
} |
87 | 16765 | } |
88 | |
|
89 | |
public void debug(String message, Throwable e) { |
90 | 0 | if (getLogLevel().compareTo(LogLevel.DEBUG) <= 0) { |
91 | 0 | print(LogLevel.DEBUG, message); |
92 | 0 | e.printStackTrace(); |
93 | |
} |
94 | |
|
95 | 0 | } |
96 | |
} |