|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mazz.i18n.Logger
public abstract class Logger
Superclass to all the loggers that provide the ability to log messages that are retrieved from a resource bundle
with the additional capability of being able to set the base bundle name and locale that this logger will use to
log the message. Note that if this object is created with a null
or unspecified locale, this logger
will use LoggerLocale
to determine what locale it should use.
This object also provides a convienent way to obtain I18N messages from the resource bundle this logger uses
in the locale this logger uses. This is useful for when you need to output messages outside of any log mechanism
(e.g. creating exceptions with a message string). See getMsg(String, Object[])
and
getMsgString(String, Object[])
.
This abstraction is to allow subclasses to utilize different logging implementations, like log4j, commons
logging, JDK logging, etc. Subclasses should/must override all constructors and simply call the super
constructors. Subclasses must implement the createLogObject(String)
/createLogObject(Class)
methods in order to create its own log implementation object. That created log object should then be used by the
subclass' implementations of the different log methods (e.g. fatal(String, Object[])
, etc).
By default, all loggers will not dump stack traces to the log when throwables are logged. To change
this default behavior, set the system property SYSPROP_DUMP_STACK_TRACES
to true
or
programatically call setDumpStackTraces(boolean)
(bear in mind that this will affect all loggers - those
that currently exist and those created in the future). Note, however, that this flag has no bearing on
Throwables logged at the FATAL level; that is to say, all Throwables that are logged at the FATAL level will
always have their stack traces dumped to the log. Additionally, all loggers will dump the resource bundle
keys that map to the messages being logged (this is to make it easier to correlate a log message to where it was
logged in the code if the message itself is in a language that cannot be read by the person looking at the log).
To change this default behavior, set the system property SYSPROP_DUMP_LOG_KEYS
to false
or
programatically call setDumpLogKeys(boolean)
. Again, this affects all loggers.
Msg
,
LoggerLocale
Field Summary | |
---|---|
static java.lang.String |
SYSPROP_DUMP_LOG_KEYS
System property name that is used to determine if the resource keys are logged along with the log message. |
static java.lang.String |
SYSPROP_DUMP_STACK_TRACES
System property name that is used to define the default dump-stack-trace behavior. |
Constructor Summary | |
---|---|
Logger(java.lang.Class clazz)
Creates a new Logger object using a default resource bundle and the default log locale as determined
by LoggerLocale . |
|
Logger(java.lang.Class clazz,
java.util.Locale locale)
Creates a new Logger object using a default resource bundle. |
|
Logger(java.lang.Class clazz,
Msg.BundleBaseName basename)
Creates a new Logger object using the default log locale as determined by LoggerLocale . |
|
Logger(java.lang.Class clazz,
Msg.BundleBaseName basename,
java.util.Locale locale)
Creates a new Logger object. |
|
Logger(java.lang.String name)
Creates a new Logger object using a default resource bundle and the default log locale as determined
by LoggerLocale . |
|
Logger(java.lang.String name,
java.util.Locale locale)
Creates a new Logger object using a default resource bundle. |
|
Logger(java.lang.String name,
Msg.BundleBaseName basename)
Creates a new Logger object using the default log locale as determined by LoggerLocale . |
|
Logger(java.lang.String name,
Msg.BundleBaseName basename,
java.util.Locale locale)
Creates a new Logger object. |
Method Summary | |
---|---|
protected abstract void |
createLogObject(java.lang.Class clazz)
Creates the actual log object to be used by this logger based on the given class. |
protected abstract void |
createLogObject(java.lang.String name)
Creates the actual log object to be used by this logger given the name of the logger as a String. |
abstract Msg |
debug(java.lang.String key,
java.lang.Object... varargs)
Logs the resource bundle message and args. |
abstract Msg |
debug(java.lang.Throwable throwable,
java.lang.String key,
java.lang.Object... varargs)
Logs the throwable with the resource bundle message and args. |
abstract Msg |
error(java.lang.String key,
java.lang.Object... varargs)
Logs the resource bundle message and args. |
abstract Msg |
error(java.lang.Throwable throwable,
java.lang.String key,
java.lang.Object... varargs)
Logs the throwable with the resource bundle message and args. |
abstract Msg |
fatal(java.lang.String key,
java.lang.Object... varargs)
Logs the resource bundle message and args. |
abstract Msg |
fatal(java.lang.Throwable throwable,
java.lang.String key,
java.lang.Object... varargs)
Logs the throwable with the resource bundle message and args. |
Msg.BundleBaseName |
getBaseBundleName()
Returns the base bundle name of the resource bundle that will house this logger's messages. |
static boolean |
getDumpLogKeys()
Gets the flag this class will use to determine if the resource bundle key names should be logged along with the log message itself. |
static boolean |
getDumpStackTraces()
Gets the flag this class will use to determine if stack traces should be logged when Throwables
are provided to the log methods. |
java.util.Locale |
getLocale()
Returns the locale of the messages that are to be logged. |
Msg |
getMsg(java.lang.String key,
java.lang.Object... varargs)
Returns a localized Msg object whose message is found in this logger's
resource bundle in the logger's locale . |
java.lang.String |
getMsgString(java.lang.String key,
java.lang.Object... varargs)
Returns a localized message string that is found in this logger's resource bundle in the logger's locale . |
abstract Msg |
info(java.lang.String key,
java.lang.Object... varargs)
Logs the resource bundle message and args. |
abstract Msg |
info(java.lang.Throwable throwable,
java.lang.String key,
java.lang.Object... varargs)
Logs the throwable with the resource bundle message and args. |
abstract boolean |
isDebugEnabled()
Returns true if the debug log level is enabled |
abstract boolean |
isErrorEnabled()
Returns true if the error log level is enabled |
abstract boolean |
isFatalEnabled()
Returns true if the fatal log level is enabled |
abstract boolean |
isInfoEnabled()
Returns true if the info log level is enabled |
abstract boolean |
isTraceEnabled()
Returns true if the trace log level is enabled |
abstract boolean |
isWarnEnabled()
Returns true if the warn log level is enabled |
static void |
setDumpLogKeys(boolean flag)
Sets the flag this class will use to determine if the resource bundle key names should be logged along with the log message itself. |
static void |
setDumpStackTraces(boolean flag)
Sets the flag this class will use to determine if stack traces should be logged when Throwable s
are provided to the log methods. |
abstract Msg |
trace(java.lang.String key,
java.lang.Object... varargs)
Logs the resource bundle message and args. |
abstract Msg |
trace(java.lang.Throwable throwable,
java.lang.String key,
java.lang.Object... varargs)
Logs the throwable with the resource bundle message and args. |
abstract Msg |
warn(java.lang.String key,
java.lang.Object... varargs)
Logs the resource bundle message and args. |
abstract Msg |
warn(java.lang.Throwable throwable,
java.lang.String key,
java.lang.Object... varargs)
Logs the throwable with the resource bundle message and args. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String SYSPROP_DUMP_STACK_TRACES
public static final java.lang.String SYSPROP_DUMP_LOG_KEYS
Constructor Detail |
---|
public Logger(java.lang.String name, Msg.BundleBaseName basename, java.util.Locale locale)
Logger
object.
name
- the name to give to the logger (this is usually a class name of the object that will be
logging messages)basename
- the base bundle name used to identify the resource bundle to use (may be null
)locale
- the locale of the messages that will be logged (may be null
)Msg.Msg(Msg.BundleBaseName, Locale)
public Logger(java.lang.Class clazz, Msg.BundleBaseName basename, java.util.Locale locale)
Logger
object.
clazz
- the class of the object that will be logging messagesbasename
- the base bundle name used to identify the resource bundle to use (may be null
)locale
- the locale of the messages that will be logged (may be null
)Msg.Msg(Msg.BundleBaseName, Locale)
public Logger(java.lang.String name, Msg.BundleBaseName basename)
Logger
object using the default log locale as determined by LoggerLocale
.
name
- the name to give to the logger (this is usually a class name of the object that will be
logging messages)basename
- the base bundle name used to identify the resource bundle to use (may be null
)Msg.Msg(Msg.BundleBaseName)
public Logger(java.lang.Class clazz, Msg.BundleBaseName basename)
Logger
object using the default log locale as determined by LoggerLocale
.
clazz
- the class of the object that will be logging messagesbasename
- the base bundle name used to identify the resource bundle to use (may be null
)Msg.Msg(Msg.BundleBaseName)
public Logger(java.lang.String name, java.util.Locale locale)
Logger
object using a default resource bundle.
name
- the name to give to the logger (this is usually a class name of the object that will be logging
messages)locale
- the locale of the messages that will be logged (may be null
)Msg.Msg(Locale)
public Logger(java.lang.Class clazz, java.util.Locale locale)
Logger
object using a default resource bundle.
clazz
- the class of the object that will be logging messageslocale
- the locale of the messages that will be logged (may be null
)Msg.Msg(Locale)
public Logger(java.lang.String name)
Logger
object using a default resource bundle and the default log locale as determined
by LoggerLocale
.
name
- the name to give to the logger (this is usually a class name of the object that will be logging
messages)Msg.Msg()
public Logger(java.lang.Class clazz)
Logger
object using a default resource bundle and the default log locale as determined
by LoggerLocale
.
clazz
- the class of the object that will be logging messagesMsg.Msg()
Method Detail |
---|
public static boolean getDumpStackTraces()
Throwables
are provided to the log methods.
public static void setDumpStackTraces(boolean flag)
Throwable
s
are provided to the log methods.
flag
- the new flag to indicate if stack traces are to be dumped to the logpublic static boolean getDumpLogKeys()
public static void setDumpLogKeys(boolean flag)
true
, this helps a person looking at the log
messages to more easily determine what a log message is and what code generated it if that person does not
understand the language that the log message was written in.
flag
- the new flag to indicate if resource bundle keys are logged along with the log messagepublic Msg.BundleBaseName getBaseBundleName()
null
, the default base bundle name will be usedMsg.getBundleBaseNameDefault()
public java.util.Locale getLocale()
null
or unspecified locale, this method will use LoggerLocale
to determine what locale to return.
public Msg getMsg(java.lang.String key, java.lang.Object... varargs)
Msg
object whose message is found in this logger's
resource bundle
in the logger's locale
.
key
- the resource bundle key of the message to getvarargs
- the resource bundle message arguments
getMsgString(String, Object[])
public java.lang.String getMsgString(java.lang.String key, java.lang.Object... varargs)
resource bundle
in the logger's locale
. This is equivalent
to getMsg(String, Object[])
.toString()
.
key
- the resource bundle key of the message to getvarargs
- the resource bundle message arguments
getMsg(String, Object[])
public abstract boolean isFatalEnabled()
true
if the fatal log level is enabled
public abstract boolean isErrorEnabled()
true
if the error log level is enabled
public abstract boolean isWarnEnabled()
true
if the warn log level is enabled
public abstract boolean isInfoEnabled()
true
if the info log level is enabled
public abstract boolean isDebugEnabled()
true
if the debug log level is enabled
public abstract boolean isTraceEnabled()
true
if the trace log level is enabled
public abstract Msg fatal(java.lang.Throwable throwable, java.lang.String key, java.lang.Object... varargs)
throwable
- the throwable to logkey
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg fatal(java.lang.String key, java.lang.Object... varargs)
key
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg error(java.lang.Throwable throwable, java.lang.String key, java.lang.Object... varargs)
throwable
- the throwable to logkey
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg error(java.lang.String key, java.lang.Object... varargs)
key
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg warn(java.lang.Throwable throwable, java.lang.String key, java.lang.Object... varargs)
throwable
- the throwable to logkey
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg warn(java.lang.String key, java.lang.Object... varargs)
key
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg info(java.lang.Throwable throwable, java.lang.String key, java.lang.Object... varargs)
throwable
- the throwable to logkey
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg info(java.lang.String key, java.lang.Object... varargs)
key
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg debug(java.lang.Throwable throwable, java.lang.String key, java.lang.Object... varargs)
throwable
- the throwable to logkey
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg debug(java.lang.String key, java.lang.Object... varargs)
key
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg trace(java.lang.Throwable throwable, java.lang.String key, java.lang.Object... varargs)
throwable
- the throwable to logkey
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
public abstract Msg trace(java.lang.String key, java.lang.Object... varargs)
key
- the resource bundle key of the message to logvarargs
- the resource bundle message arguments
protected abstract void createLogObject(java.lang.Class clazz)
clazz
- the class to associate with the log object that is to be createdprotected abstract void createLogObject(java.lang.String name)
name
- the name to associate with the log object that is to be created
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |