Class Logger
console.log that uses categories, log levels, and a predefined log
format.
The different log methods delegate to the corresponding methods in console:
error(String, Object...)→console.error()warn(String, Object...)→console.warn()info(String, Object...)→console.info()debug(String, Object...)→console.debug()
You can use an arbitrary string as a category. By using a hierarchical category, you can override subcategories. String substitutions are supported, and you can pass a variable list of parameters to the log methods.
The log level is set globally for all categories using setLevel(Level).
You can override the level for one category using setLevel(String, Level).
To reset a category, use resetLevel(String). If the category contains .,
it is interpreted hierarchically. This means that if the category org.jboss is overridden,
this is also applied to all subcategories (unless overridden otherwise).
The log format is predefined as
HH:mm:ss.SSS <level> [<category>] <message>and cannot be customized. If the category is a fully qualified class name, the package names are shortened. In any case the category is trimmed and right-aligned.
The logger exports some methods with slightly adjusted signatures to JavaScript. You can use them, for instance, in the browser dev tools to control the global and category-based log levels:
org.jboss.elemento.logger.Logger.setLevel(String level)- sets the global log levelorg.jboss.elemento.logger.Logger.setLevel(String category, String level)- overrides the log level for one categoryorg.jboss.elemento.logger.Logger.resetLevel(String category)- resets the log level for the category to the global log level
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidstatic LoggerRetrieves or creates a logger with the specified category.voidgroupDebug(String message, Object... params) voidgroupEnd()voidgroupError(String message, Object... params) voidvoidvoidstatic voidSets the global log level from the "log-level" query parameter.static voidSets the global log level from the specified query parameter.booleanstatic voidresetLevel(String category) Resets the log level for the specified category to the global log level.static voidSets the log level for a given category.static voidSets the global log level.voidtimeDebugLog(String timer, Object... params) voidvoidtimeErrorLog(String timer, Object... params) voidtimeInfoLog(String timer, Object... params) voidtimeWarnLog(String timer, Object... params) void
-
Field Details
-
DEFAULT_LEVEL
-
LOG_LEVEL_PARAMETER
- See Also:
-
-
Method Details
-
initFrom
Sets the global log level from the "log-level" query parameter. If no query parameter was given, this method does nothing. -
initFrom
-
getLogger
-
setLevel
Sets the global log level.- Parameters:
level- the desired log level to be set
-
setLevel
-
resetLevel
Resets the log level for the specified category to the global log level.- Parameters:
category- the category for which the log level needs to be reset
-
debug
-
info
-
warn
-
error
-
isEnabled
-
groupDebug
-
groupInfo
-
groupWarn
-
groupError
-
groupEnd
public void groupEnd() -
timeDebug
-
timeDebugLog
-
timeInfo
-
timeInfoLog
-
timeWarn
-
timeWarnLog
-
timeError
-
timeErrorLog
-
timeEnd
-