Class Logger
- java.lang.Object
-
- eu.woolplatform.utils.log.Logger
-
public class Logger extends Object
This class can be used for writing log output. It has a number of static methods to send a log message at a specific level. The supported levels in order from most urgent to least urgent are:
The actual behaviour of the logger is determined by the
LogDelegatewhich is set withsetLogDelegate(). The default is aDefaultLogDelegate, which writes messages to standard output or standard error. Normally the log delegate should be set and configured once at the start of the application.Each log method takes a
tagparameter. This should be a tag that identifies the source of the log. A log delegate may apply different log levels for different tags. For example one tag may be logged up to the levelDEBUG, while another tag is only logged up to the levelWARN.Note that it may require computation time and resources to construct a log message, and this is not necessary if eventually the message is not written because of the log level. To avoid the construction costs, you may check
isLoggable()first.
-
-
Constructor Summary
Constructors Constructor Description Logger()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intd(String tag, String msg)Writes a message at levelDEBUG.static intd(String tag, String msg, Throwable tr)Writes a message at levelDEBUG.static inte(String tag, String msg)Writes a message at levelERROR.static inte(String tag, String msg, Throwable tr)Writes a message at levelERROR.static LogDelegategetLogDelegate()Returns the log delegate.static StringgetStackTraceString(Throwable tr)Returns the stack trace string for the specified exception.static inti(String tag, String msg)Writes a message at levelINFO.static inti(String tag, String msg, Throwable tr)Writes a message at levelINFO.static booleanisLoggable(String tag, int level)Determines if messages at the specified level are logged for the specified tag.static intprintln(int priority, String tag, String msg)Writes a log message.static voidsetLogDelegate(LogDelegate delegate)Sets the log delegate.static intv(String tag, String msg)Writes a message at levelVERBOSE.static intv(String tag, String msg, Throwable tr)Writes a message at levelVERBOSE.static intw(String tag, String msg)Writes a message at levelWARN.static intw(String tag, String msg, Throwable tr)Writes a message at levelWARN.static intw(String tag, Throwable tr)Writes a message at levelWARN.static intwtf(String tag, String msg)Writes a message at levelASSERT.static intwtf(String tag, String msg, Throwable tr)Writes a message at levelASSERT.static intwtf(String tag, Throwable tr)Writes a message at levelASSERT.
-
-
-
Field Detail
-
VERBOSE
public static final int VERBOSE
- See Also:
- Constant Field Values
-
DEBUG
public static final int DEBUG
- See Also:
- Constant Field Values
-
INFO
public static final int INFO
- See Also:
- Constant Field Values
-
WARN
public static final int WARN
- See Also:
- Constant Field Values
-
ERROR
public static final int ERROR
- See Also:
- Constant Field Values
-
ASSERT
public static final int ASSERT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setLogDelegate
public static void setLogDelegate(LogDelegate delegate)
Sets the log delegate. See the top of this page for more information.- Parameters:
delegate- the log delegate
-
getLogDelegate
public static LogDelegate getLogDelegate()
Returns the log delegate.- Returns:
- the log delegate
-
d
public static int d(String tag, String msg, Throwable tr)
Writes a message at levelDEBUG.- Parameters:
tag- the tagmsg- the messagetr- an exception- Returns:
- 0 if no error occurred, an error code otherwise
-
d
public static int d(String tag, String msg)
Writes a message at levelDEBUG.- Parameters:
tag- the tagmsg- the message- Returns:
- 0 if no error occurred, an error code otherwise
-
e
public static int e(String tag, String msg)
Writes a message at levelERROR.- Parameters:
tag- the tagmsg- the message- Returns:
- 0 if no error occurred, an error code otherwise
-
e
public static int e(String tag, String msg, Throwable tr)
Writes a message at levelERROR.- Parameters:
tag- the tagmsg- the messagetr- an exception- Returns:
- 0 if no error occurred, an error code otherwise
-
getStackTraceString
public static String getStackTraceString(Throwable tr)
Returns the stack trace string for the specified exception. The returned string probably contains new lines, but it does not have a trailing new line.- Parameters:
tr- the exception- Returns:
- the stack trace string
-
i
public static int i(String tag, String msg, Throwable tr)
Writes a message at levelINFO.- Parameters:
tag- the tagmsg- the messagetr- an exception- Returns:
- 0 if no error occurred, an error code otherwise
-
i
public static int i(String tag, String msg)
Writes a message at levelINFO.- Parameters:
tag- the tagmsg- the message- Returns:
- 0 if no error occurred, an error code otherwise
-
isLoggable
public static boolean isLoggable(String tag, int level)
Determines if messages at the specified level are logged for the specified tag.- Parameters:
tag- the taglevel- the level- Returns:
- true if the message will be logged, false otherwise
-
println
public static int println(int priority, String tag, String msg)Writes a log message.- Parameters:
priority- the log leveltag- the tagmsg- the message- Returns:
- 0 if no error occurred, an error code otherwise
-
v
public static int v(String tag, String msg, Throwable tr)
Writes a message at levelVERBOSE.- Parameters:
tag- the tagmsg- the messagetr- an exception or null- Returns:
- 0 if no error occurred, an error code otherwise
-
v
public static int v(String tag, String msg)
Writes a message at levelVERBOSE.- Parameters:
tag- the tagmsg- the message- Returns:
- 0 if no error occurred, an error code otherwise
-
w
public static int w(String tag, String msg)
Writes a message at levelWARN.- Parameters:
tag- the tagmsg- the message- Returns:
- 0 if the message was written successfully, an error code otherwise
-
w
public static int w(String tag, Throwable tr)
Writes a message at levelWARN.- Parameters:
tag- the tagtr- an exception or null- Returns:
- 0 if no error occurred, an error code otherwise
-
w
public static int w(String tag, String msg, Throwable tr)
Writes a message at levelWARN.- Parameters:
tag- the tagmsg- the messagetr- an exception or null- Returns:
- 0 if no error occurred, an error code otherwise
-
wtf
public static int wtf(String tag, String msg)
Writes a message at levelASSERT.- Parameters:
tag- the tagmsg- the message- Returns:
- 0 if no error occurred, an error code otherwise
-
wtf
public static int wtf(String tag, Throwable tr)
Writes a message at levelASSERT.- Parameters:
tag- the tagtr- an exception or null- Returns:
- 0 if no error occurred, an error code otherwise
-
-