-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathLogger.java
More file actions
218 lines (182 loc) · 5.81 KB
/
Logger.java
File metadata and controls
218 lines (182 loc) · 5.81 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* #%L
* SciJava Common shared library for SciJava software.
* %%
* Copyright (C) 2009 - 2026 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.log;
import static org.scijava.log.LogLevel.DEBUG;
import static org.scijava.log.LogLevel.ERROR;
import static org.scijava.log.LogLevel.INFO;
import static org.scijava.log.LogLevel.TRACE;
import static org.scijava.log.LogLevel.WARN;
/**
* Interface for objects which can produce log messages.
* <p>
* It provides methods for logging messages, exception stack traces and
* combinations of the two.
* </p>
*
* @author Curtis Rueden
* @see LogLevel
* @see LogService
*/
@IgnoreAsCallingClass
public interface Logger {
default void debug(final Object msg) {
log(DEBUG, msg);
}
default void debug(final Throwable t) {
log(DEBUG, t);
}
default void debug(final Object msg, final Throwable t) {
log(DEBUG, msg, t);
}
default void error(final Object msg) {
log(ERROR, msg);
}
default void error(final Throwable t) {
log(ERROR, t);
}
default void error(final Object msg, final Throwable t) {
log(ERROR, msg, t);
}
default void info(final Object msg) {
log(INFO, msg);
}
default void info(final Throwable t) {
log(INFO, t);
}
default void info(final Object msg, final Throwable t) {
log(INFO, msg, t);
}
default void trace(final Object msg) {
log(TRACE, msg);
}
default void trace(final Throwable t) {
log(TRACE, t);
}
default void trace(final Object msg, final Throwable t) {
log(TRACE, msg, t);
}
default void warn(final Object msg) {
log(WARN, msg);
}
default void warn(final Throwable t) {
log(WARN, t);
}
default void warn(final Object msg, final Throwable t) {
log(WARN, msg, t);
}
default boolean isDebug() {
return isLevel(DEBUG);
}
default boolean isError() {
return isLevel(ERROR);
}
default boolean isInfo() {
return isLevel(INFO);
}
default boolean isTrace() {
return isLevel(TRACE);
}
default boolean isWarn() {
return isLevel(WARN);
}
default boolean isLevel(final int level) {
return getLevel() >= level;
}
/**
* Logs a message.
*
* @param level The level at which the message will be logged. If the current
* level (given by {@link #getLevel()} is below this one, no logging
* is performed.
* @param msg The message to log.
*/
default void log(final int level, final Object msg) {
log(level, msg, null);
}
/**
* Logs an exception.
*
* @param level The level at which the exception will be logged. If the
* current level (given by {@link #getLevel()} is below this one, no
* logging is performed.
* @param t The exception to log.
*/
default void log(final int level, final Throwable t) {
log(level, null, t);
}
/**
* Logs a message with an exception.
*
* @param level The level at which the information will be logged. If the
* current level (given by {@link #getLevel()} is below this one, no
* logging is performed.
* @param msg The message to log.
* @param t The exception to log.
*/
default void log(final int level, final Object msg, final Throwable t) {
if (isLevel(level)) alwaysLog(level, msg, t);
}
/**
* Logs a message with an exception. This message will always be logged even
* if its level is above the current level (given by {@link #getLevel()}).
*
* @param level The level at which the information will be logged.
* @param msg The message to log.
* @param t The exception to log.
*/
void alwaysLog(int level, Object msg, Throwable t);
/** Returns the name of this logger. */
default String getName() {
return getSource().name();
}
/** Returns the {@link LogSource} associated with this logger. */
LogSource getSource();
/** Returns the log level of this logger. see {@link LogLevel} */
int getLevel();
/**
* Creates a sub logger, that forwards the message it gets to this logger. The
* sub logger will have the same log level as this logger.
*/
default Logger subLogger(String name) {
return subLogger(name, getLevel());
}
/**
* Creates a sub logger, that forwards the message it gets to this logger.
*
* @param name The name of the sub logger.
* @param level The log level of the sub logger.
*/
Logger subLogger(String name, int level);
/** Adds an item to the list of registered listeners. */
void addLogListener(LogListener listener);
/** Removes an item from the list of registered listeners. */
void removeLogListener(LogListener listener);
/** Broadcasts the given log message to the registered listeners. */
void notifyListeners(final LogMessage message);
}