public class LOGGER extends Object
// set log level LOGGER.setMinLevel (LOGGER.WARN); //write to std::out? LOGGER.setLogToStdOut (true); //write to std::err? LOGGER.setLogToStdErr (true); //write to a file? LOGGER.setLogFile (new File ("/my/log/file")); LOGGER.setLogToFile (true);If you don't initialize the LOGGER it defaults to printing to only warning and error messages sdt::err. Of course all these methods can be used from wherever you want. To log a message just call one of the following functions:
LOGGER.debug ("message", [EXCEPTION]) | log a debug message |
---|---|
LOGGER.info ("message", [EXCEPTION]) | log an info message |
LOGGER.warn ("message", [EXCEPTION]) | log a warn message |
LOGGER.error ("message", [EXCEPTION]) | log an error message |
LOGGER.closeLogger ()
in order to clean up and close the file stream.Modifier and Type | Field and Description |
---|---|
static SimpleDateFormat |
dateformat
The Constant date format that is used in log messages.
|
static int |
DEBUG
The Constant DEBUG.
|
static int |
ERROR
The Constant ERROR.
|
static int |
INFO
The Constant INFO.
|
protected static int |
logLevel
The log level, defaults to warning and error messages.
|
static String |
NEWLINE
The os independent new line char
|
static int |
WARN
The Constant WARN.
|
Constructor and Description |
---|
LOGGER() |
Modifier and Type | Method and Description |
---|---|
static void |
addCallback(LogCallback callBack) |
static void |
addLevel(int level)
Adds a log level.
|
static void |
closeLogger()
Close the logger.
|
static void |
debug(Exception e,
Object... msg)
Log a debug message.
|
static void |
debug(Object... msg)
Log a debug message.
|
static void |
debug(String msg,
Exception e)
Deprecated.
use
debug(Exception e, String... msg) instead |
static void |
error(Exception e,
Object... msg)
Log an error.
|
static void |
error(Object... msg)
Log an error.
|
static void |
error(String msg,
Exception e)
Deprecated.
use
error(Exception e, String... msg) instead |
static boolean |
hasLevel(int level)
Checks for a log level.
|
static void |
info(Exception e,
Object... msg)
Log an info message.
|
static void |
info(Object... msg)
Log an info message.
|
static void |
info(String msg,
Exception e)
Deprecated.
use
info(Exception e, String... msg) instead |
static boolean |
isDebugEnabled()
Checks if debug is enabled.
|
static boolean |
isErrorEnabled()
Checks if error is enabled.
|
static boolean |
isInfoEnabled()
Checks if info is enabled.
|
static boolean |
isWarnEnabled()
Checks if warn is enabled.
|
static void |
rmCallBack(LogCallback callBack) |
static void |
rmLevel(int level)
Removes a level.
|
static void |
setLevel(int level)
Sets the exclusive level.
|
static boolean |
setLogFile(File file)
Define the file to write the logs to.
|
static boolean |
setLogFile(String fileName)
Define the file to write the log to.
|
static void |
setLogStackTrace(boolean log)
Should we log stack traces? If you pass
true you'll find a stacktrace after the log message which passed an exception, otherwise (default) only the exception class and the corresponding message will be logged. |
static boolean |
setLogToFile(boolean log)
Should we write to the log file? Only successful if log file was defined previously.
|
static void |
setLogToStdErr(boolean log)
Should we log to std::err? default:
true |
static void |
setLogToStdOut(boolean log)
Should we log to std::out? default:
false |
static void |
setMinLevel(int level)
Sets the min log level.
|
static void |
warn(Exception e,
Object... msg)
Log a warning message.
|
static void |
warn(Object... msg)
Log a warning message.
|
static void |
warn(String msg,
Exception e)
Deprecated.
use
warn(Exception e, String... msg) instead |
public static final int ERROR
public static final int WARN
public static final int INFO
public static final int DEBUG
public static final SimpleDateFormat dateformat
dd.MM HH:mm:ss
, e.g. 27.10 18:55:49
public static final String NEWLINE
protected static int logLevel
public static boolean setLogFile(String fileName)
LOGGER.setLogToFile (true)
to start writing to log file. Same as LOGGER.setLogFile (new File (fileName))
fileName
- the log filepublic static boolean setLogFile(File file)
LOGGER.setLogToFile (true)
to start writing to log file.file
- the log filepublic static void closeLogger()
public static boolean setLogToFile(boolean log)
LOGGER.setLogFile (file)
)log
- should we log to file?public static void setLogStackTrace(boolean log)
true
you'll find a stacktrace after the log message which passed an exception, otherwise (default) only the exception class and the corresponding message will be logged.log
- should we log stack traces?public static void setLogToStdErr(boolean log)
true
log
- should we log to std:err?public static void setLogToStdOut(boolean log)
false
log
- the log to std outpublic static void setMinLevel(int level)
LOGGER.DEBUG
, LOGGER.INFO
, LOGGER.WARN
, LOGGER.ERROR
. By default the min level is LOGGER.WARN
. Thus, LOGGER.setMinLevel (LOGGER.INFO)
enables logging for INFO
, WARN
, and ERROR
messages.level
- the min levelpublic static void setLevel(int level)
LOGGER.setLevel (LOGGER.INFO)
enables logging only for INFO
messages.level
- the levelpublic static void addLevel(int level)
INFO
was enabled, LOGGER.addLevel (LOGGER.ERROR)
enables logging only for INFO
and ERROR
messages.level
- the levelpublic static void rmLevel(int level)
INFO
and ERROR
was enabled, LOGGER.rmLevel (LOGGER.INFO)
enables logging only for ERROR
messages.level
- the levelpublic static boolean hasLevel(int level)
level
- the levelpublic static boolean isInfoEnabled()
public static boolean isDebugEnabled()
public static boolean isErrorEnabled()
public static boolean isWarnEnabled()
@Deprecated public static void error(String msg, Exception e)
error(Exception e, String... msg)
insteadmsg
- the msge
- the thrown exception@Deprecated public static void info(String msg, Exception e)
info(Exception e, String... msg)
insteadmsg
- the msge
- the thrown exception@Deprecated public static void debug(String msg, Exception e)
debug(Exception e, String... msg)
insteadmsg
- the msge
- the thrown exception@Deprecated public static void warn(String msg, Exception e)
warn(Exception e, String... msg)
insteadmsg
- the msge
- the thrown exceptionpublic static void error(Exception e, Object... msg)
msg
- the msge
- the thrown exceptionpublic static void info(Exception e, Object... msg)
msg
- the msge
- the thrown exceptionpublic static void debug(Exception e, Object... msg)
msg
- the msge
- the thrown exceptionpublic static void warn(Exception e, Object... msg)
msg
- the msge
- the thrown exceptionpublic static void error(Object... msg)
msg
- the msgpublic static void info(Object... msg)
msg
- the msgpublic static void debug(Object... msg)
msg
- the msgpublic static void warn(Object... msg)
msg
- the msgpublic static void addCallback(LogCallback callBack)
public static void rmCallBack(LogCallback callBack)
Copyright © 2014. All rights reserved.