Skip to content

Commit 8633aa8

Browse files
committed
WIP: Logger dummy
1 parent 60664db commit 8633aa8

File tree

1 file changed

+208
-0
lines changed

1 file changed

+208
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
2+
package org.scijava.util;
3+
4+
import static org.scijava.log.LogLevel.DEBUG;
5+
import static org.scijava.log.LogLevel.ERROR;
6+
import static org.scijava.log.LogLevel.INFO;
7+
import static org.scijava.log.LogLevel.TRACE;
8+
import static org.scijava.log.LogLevel.WARN;
9+
10+
import org.scijava.log.LogLevel;
11+
import org.scijava.log.LogListener;
12+
import org.scijava.log.LogMessage;
13+
import org.scijava.log.LogSource;
14+
15+
/**
16+
* TODO: Dummy class. To be replaced or properly implemented later. See:
17+
* {@literal https://github.com/scijava/scijava-ops/issues/13}
18+
*/
19+
public class Logger {
20+
21+
private Logger() {
22+
// Static utility class
23+
}
24+
25+
public static void debug(final Object msg) {
26+
log(DEBUG, msg);
27+
}
28+
29+
public static void debug(final Throwable t) {
30+
log(DEBUG, t);
31+
}
32+
33+
public static void debug(final Object msg, final Throwable t) {
34+
log(DEBUG, msg, t);
35+
}
36+
37+
public static void error(final Object msg) {
38+
log(ERROR, msg);
39+
}
40+
41+
public static void error(final Throwable t) {
42+
log(ERROR, t);
43+
}
44+
45+
public static void error(final Object msg, final Throwable t) {
46+
log(ERROR, msg, t);
47+
}
48+
49+
public static void info(final Object msg) {
50+
log(INFO, msg);
51+
}
52+
53+
public static void info(final Throwable t) {
54+
log(INFO, t);
55+
}
56+
57+
public static void info(final Object msg, final Throwable t) {
58+
log(INFO, msg, t);
59+
}
60+
61+
public static void trace(final Object msg) {
62+
log(TRACE, msg);
63+
}
64+
65+
public static void trace(final Throwable t) {
66+
log(TRACE, t);
67+
}
68+
69+
public static void trace(final Object msg, final Throwable t) {
70+
log(TRACE, msg, t);
71+
}
72+
73+
public static void warn(final Object msg) {
74+
log(WARN, msg);
75+
}
76+
77+
public static void warn(final Throwable t) {
78+
log(WARN, t);
79+
}
80+
81+
public static void warn(final Object msg, final Throwable t) {
82+
log(WARN, msg, t);
83+
}
84+
85+
public static boolean isDebug() {
86+
return isLevel(DEBUG);
87+
}
88+
89+
public static boolean isError() {
90+
return isLevel(ERROR);
91+
}
92+
93+
public static boolean isInfo() {
94+
return isLevel(INFO);
95+
}
96+
97+
public static boolean isTrace() {
98+
return isLevel(TRACE);
99+
}
100+
101+
public static boolean isWarn() {
102+
return isLevel(WARN);
103+
}
104+
105+
public static boolean isLevel(final int level) {
106+
return getLevel() >= level;
107+
}
108+
109+
/**
110+
* Logs a message.
111+
*
112+
* @param level The level at which the message will be logged. If the current
113+
* level (given by {@link #getLevel()} is below this one, no logging
114+
* is performed.
115+
* @param msg The message to log.
116+
*/
117+
public static void log(final int level, final Object msg) {
118+
log(level, msg, null);
119+
}
120+
121+
/**
122+
* Logs an exception.
123+
*
124+
* @param level The level at which the exception will be logged. If the
125+
* current level (given by {@link #getLevel()} is below this one, no
126+
* logging is performed.
127+
* @param t The exception to log.
128+
*/
129+
public static void log(final int level, final Throwable t) {
130+
log(level, null, t);
131+
}
132+
133+
/**
134+
* Logs a message with an exception.
135+
*
136+
* @param level The level at which the information will be logged. If the
137+
* current level (given by {@link #getLevel()} is below this one, no
138+
* logging is performed.
139+
* @param msg The message to log.
140+
* @param t The exception to log.
141+
*/
142+
public static void log(final int level, final Object msg, final Throwable t) {
143+
if (isLevel(level)) alwaysLog(level, msg, t);
144+
}
145+
146+
/**
147+
* Logs a message with an exception. This message will always be logged even
148+
* if its level is above the current level (given by {@link #getLevel()}).
149+
*
150+
* @param level The level at which the information will be logged.
151+
* @param msg The message to log.
152+
* @param t The exception to log.
153+
*/
154+
public static void alwaysLog(final int level, final Object msg,
155+
final Throwable t)
156+
{
157+
throw new UnsupportedOperationException("not yet implemented");
158+
}
159+
160+
/** Returns the name of this logger. */
161+
public static String getName() {
162+
return getSource().name();
163+
}
164+
165+
/** Returns the {@link LogSource} associated with this logger. */
166+
public static LogSource getSource() {
167+
throw new UnsupportedOperationException("not yet implemented");
168+
}
169+
170+
/** Returns the log level of this logger. see {@link LogLevel} */
171+
public static int getLevel() {
172+
throw new UnsupportedOperationException("not yet implemented");
173+
}
174+
175+
/**
176+
* Creates a sub logger, that forwards the message it gets to this logger. The
177+
* sub logger will have the same log level as this logger.
178+
*/
179+
public static Logger subLogger(final String name) {
180+
return subLogger(name, getLevel());
181+
}
182+
183+
/**
184+
* Creates a sub logger, that forwards the message it gets to this logger.
185+
*
186+
* @param name The name of the sub logger.
187+
* @param level The log level of the sub logger.
188+
*/
189+
public static Logger subLogger(final String name, final int level) {
190+
throw new UnsupportedOperationException("not yet implemented");
191+
}
192+
193+
/** Adds an item to the list of registered listeners. */
194+
public void addLogListener(final LogListener listener) {
195+
throw new UnsupportedOperationException("not yet implemented");
196+
}
197+
198+
/** Removes an item from the list of registered listeners. */
199+
public void removeLogListener(final LogListener listener) {
200+
throw new UnsupportedOperationException("not yet implemented");
201+
}
202+
203+
/** Broadcasts the given log message to the registered listeners. */
204+
public void notifyListeners(final LogMessage message) {
205+
throw new UnsupportedOperationException("not yet implemented");
206+
}
207+
208+
}

0 commit comments

Comments
 (0)