Logger
Elemento contains a small wrapper around console.log
that uses categories, log levels, and a predefined log format.
The different log methods delegate to the corresponding methods in console
:
Logger.error(String, Object... params)
→console.error()
Logger.warn(String, Object... params)
→console.warn()
Logger.info(String, Object... params)
→console.info()
Logger.debug(String, Object... params)
→console.debug()
Get loggers
To get a logger, use Logger.getLogger(String category)
.
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 Logger.setLevel(Level level)
. You can override the level for one category using Logger.setLevel(String category, Level level)
. To reset a category, use Logger.resetLevel(String category)
. 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).
Log format
The log format is predefined as
and cannot be customized. The package names are shortened if the category is a fully qualified class name. In any case, the category is trimmed and right-aligned.
Controlling log levels from JavaScript
The logger module 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
Please use the fully qualified name!
Dependency
Add the following dependency to use elemento-logger
:
In your GWT module, inherit from org.jboss.elemento.Logger
:
Last updated