Package com.iizix
Class Loggers
- java.lang.Object
- com.iizix.Loggers
public class Loggers extends java.lang.Object
The class that manages allILog
instances in the process and it's threads or thread groups. If no special assignedLoggers
instance is found using theILoggers
interface, the default one is used.The following arguments are converted using "deep-toString" meaning their contents and subcontents are deep-toString'eg if possible, otherwise just as "toString()".
- null: "null".
- Array of primitives: the entire array is expanded.
- com.iizix.prop.StringMapProp or java.util.Map: lists all the contents on new lines as " - key = value".
- Throwable: expanded throwable with stack trace, including potential ignored exception and cause.
- Author:
- Christopher Mindus
Field Summary
Fields Modifier and Type Field Description static java.lang.String
INDENT
The indent string used when parameters are on new lines.static java.lang.String
prependString
The string that is prepended to all logged messages when written toSystem.out
when no ILoggerRedirector is present.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Thread
createThread(java.lang.Runnable r, java.lang.String name)
Creates a new Thread with a specific name and an associated logger.static java.lang.Thread
createThread(java.lang.Runnable r, java.lang.String name, java.lang.Object o)
Creates a new Thread with a specific name and an associated logger along with an attached thread object, typically an instance of SessionInfo.static java.lang.Thread
createThread(java.lang.ThreadGroup tg, java.lang.Runnable r, java.lang.String name)
Creates a new Thread with a specific name and an associated logger.static java.lang.Thread
createThread(java.lang.ThreadGroup tg, java.lang.Runnable r, java.lang.String name, java.lang.Object o)
Creates a new Thread with a specific name and an associated logger.static java.lang.ThreadGroup
createThreadGroup(java.lang.String name)
Creates a new Thread Group with a specific name and an associated logger.static java.lang.ThreadGroup
createThreadGroup(java.lang.String name, java.lang.Object o)
Creates a new Thread Group with a specific name and an associated logger.static java.lang.ThreadGroup
createThreadGroup(java.lang.ThreadGroup parent, java.lang.String name)
Creates a new Thread Group with a specific name and an associated logger.static java.lang.ThreadGroup
createThreadGroup(java.lang.ThreadGroup parent, java.lang.String name, java.lang.Object o)
Creates a new Thread Group with a specific name and an associated logger.static Loggers
getCurrent()
Method to get theLoggers
instance from the calling thread.static Loggers
getDefault()
Gets the default instance of theLoggers
.static java.lang.String
getLevelString(int level)
Gets the level string.static java.lang.String
getLevelStringFormatted(int level)
Gets the formatted level string that is adjusted with spaces and surrounded with [].int
getLogLevel()
Gets the log level.java.lang.String
getName()
Gets the name of this logger.static ILoggerRedirector
getRedirector()
Sets the log redirector used when redirecting an event from client to server.static java.lang.Object
getTObject()
Gets the thread object or thread group object for the calling thread.static void
log(int level, java.lang.String clazz, java.lang.String msg)
Logs an event to the logger of the current thread or thread group.static void
log(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param)
Logs an event to the logger of the current thread or thread group.static void
log(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object... params)
Logs an event to the logger of the current thread or thread group.static void
log(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param1, java.lang.Object param2)
Logs an event to the logger of the current thread or thread group.static void
logForced(int level, java.lang.String clazz, java.lang.String msg)
Logs an event to the logger of the current thread or thread group.static void
logForced(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param)
Forces logging of an event to the logger of the current thread or thread group.static void
logForced(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object... params)
Forces logging of an event to the logger of the current thread or thread group.static void
logForced(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param1, java.lang.Object param2)
Forces logging of an event to the logger of the current thread or thread group.void
setLogLevel(int level)
Changes the log level.static boolean
setRedirector(ILoggerRedirector newRedirector)
Sets the log redirector used when redirecting an event from client to server.static void
stdoutPrintln(java.lang.String text)
Logs to console output.
Field Detail
INDENT
public static final java.lang.String INDENT
The indent string used when parameters are on new lines.- See Also:
- Constant Field Values
prependString
public static java.lang.String prependString
The string that is prepended to all logged messages when written toSystem.out
when no ILoggerRedirector is present.
Method Detail
stdoutPrintln
public static void stdoutPrintln(java.lang.String text)
Logs to console output.- Parameters:
text
- Prints a text with line feed to the console bypassing a potential redirection.
getLevelString
public static java.lang.String getLevelString(int level)
Gets the level string.- Parameters:
level
- The level.- Returns:
- The string, or UNKNOWN if level is wrong.
getLevelStringFormatted
public static java.lang.String getLevelStringFormatted(int level)
Gets the formatted level string that is adjusted with spaces and surrounded with [].- Parameters:
level
- The log level (1-7).- Returns:
- The formatted log string.
getDefault
public static Loggers getDefault()
Gets the default instance of theLoggers
.- Returns:
- The default Loggers instance.
getRedirector
public static ILoggerRedirector getRedirector()
Sets the log redirector used when redirecting an event from client to server.- Returns:
- logRedirector, the log redirector or
null
for none.
setRedirector
public static boolean setRedirector(ILoggerRedirector newRedirector)
Sets the log redirector used when redirecting an event from client to server.- Parameters:
newRedirector
- the new redirector ornull
for none.- Returns:
- true if the setting changed, false if same value was present.
getCurrent
public static Loggers getCurrent()
Method to get theLoggers
instance from the calling thread.- Returns:
- The current Loggers instance of the calling thread.
log
public static void log(int level, java.lang.String clazz, java.lang.String msg)
Logs an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.
log
public static void log(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param)
Logs an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.param
- The parameter, or null for none.
log
public static void log(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param1, java.lang.Object param2)
Logs an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.param1
- The first parameter, or null for none.param2
- The second parameter, or null for none.
log
public static void log(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object... params)
Logs an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.params
- The list of parameters, or null for none.
logForced
public static void logForced(int level, java.lang.String clazz, java.lang.String msg)
Logs an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.
logForced
public static void logForced(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param)
Forces logging of an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.param
- The parameter, or null for none.
logForced
public static void logForced(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object param1, java.lang.Object param2)
Forces logging of an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.param1
- The first parameter, or null for none.param2
- The second parameter, or null for none.
logForced
public static void logForced(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object... params)
Forces logging of an event to the logger of the current thread or thread group.- Parameters:
level
- The log level.clazz
- Event originates from class or logger name.msg
- The message.params
- The list of parameters, or null for none.
createThread
public static java.lang.Thread createThread(java.lang.Runnable r, java.lang.String name)
Creates a new Thread with a specific name and an associated logger.- Parameters:
r
- The Runnable.name
- The name of the thread and the Loggers instance.- Returns:
- A new Loggers enabled thread.
createThread
public static java.lang.Thread createThread(java.lang.Runnable r, java.lang.String name, java.lang.Object o)
Creates a new Thread with a specific name and an associated logger along with an attached thread object, typically an instance of SessionInfo.- Parameters:
r
- The Runnable.name
- The name of the thread and the Loggers instance.o
- An object or null for none.- Returns:
- A new Loggers enabled thread.
createThread
public static java.lang.Thread createThread(java.lang.ThreadGroup tg, java.lang.Runnable r, java.lang.String name)
Creates a new Thread with a specific name and an associated logger.- Parameters:
tg
- The ThreadGroup.r
- The Runnable.name
- The name of the thread and the Loggers instance.- Returns:
- A new Loggers enabled thread.
createThread
public static java.lang.Thread createThread(java.lang.ThreadGroup tg, java.lang.Runnable r, java.lang.String name, java.lang.Object o)
Creates a new Thread with a specific name and an associated logger.- Parameters:
tg
- The ThreadGroup.r
- The Runnable.name
- The name of the thread and the Loggers instance.o
- An object or null for none.- Returns:
- A new Loggers enabled thread.
createThreadGroup
public static java.lang.ThreadGroup createThreadGroup(java.lang.String name)
Creates a new Thread Group with a specific name and an associated logger.- Parameters:
name
- The name of the thread and the Loggers instance.- Returns:
- A new Loggers enabled thread group.
createThreadGroup
public static java.lang.ThreadGroup createThreadGroup(java.lang.String name, java.lang.Object o)
Creates a new Thread Group with a specific name and an associated logger.- Parameters:
name
- The name of the thread and the Loggers instance.o
- An object or null for none.- Returns:
- A new Loggers enabled thread group.
createThreadGroup
public static java.lang.ThreadGroup createThreadGroup(java.lang.ThreadGroup parent, java.lang.String name)
Creates a new Thread Group with a specific name and an associated logger.- Parameters:
parent
- The parent thread group.name
- The name of the thread and the Loggers instance.- Returns:
- A new Loggers enabled thread group.
createThreadGroup
public static java.lang.ThreadGroup createThreadGroup(java.lang.ThreadGroup parent, java.lang.String name, java.lang.Object o)
Creates a new Thread Group with a specific name and an associated logger.- Parameters:
parent
- The parent thread group.name
- The name of the thread and the Loggers instance.o
- An object or null for none.- Returns:
- A new Loggers enabled thread group.
getTObject
public static java.lang.Object getTObject()
Gets the thread object or thread group object for the calling thread. If the thread has been created in this class usingcreateThread
, but without a thread object (or if it is null), the thread group (and parent thread groups) will be searched for such an object.- Returns:
- Object The object of the thread or thread group, or null for none.
getName
public java.lang.String getName()
Gets the name of this logger.- Returns:
- A String that is never null, but empty string.
setLogLevel
public void setLogLevel(int level)
Changes the log level.- Parameters:
level
- The new level as:- 0 = Use default logger.
- 1 =
ILog.SEVERE
- 2 =
ILog.WARNING
- 3 =
ILog.INFO
- 4 =
ILog.CONFIG
- 5 =
ILog.FINE
- 6 =
ILog.FINER
- 7 =
ILog.FINEST
- Throws:
java.lang.IllegalArgumentException
- If the value is less than (0) zero or larger than (7) seven.
getLogLevel
public int getLogLevel()
Gets the log level.- Returns:
- A value of:
- 1 =
ILog.SEVERE
- 2 =
ILog.WARNING
- 3 =
ILog.INFO
- 4 =
ILog.CONFIG
- 5 =
ILog.FINE
- 6 =
ILog.FINER
- 7 =
ILog.FINEST
- 1 =