Package org.jboss.elemento.logger
console.log that uses categories, log levels, and
a predefined log format.
Getting Loggers
Retrieve a logger using Logger.getLogger(String) with an arbitrary category string. Using hierarchical categories
(such as fully qualified class names) enables level overrides for subcategories:
package org.acme;
public class Foo {
private static final Logger logger = Logger.getLogger(Foo.class.getName());
public void bar() {
logger.info("Processing request");
logger.debug("Request details: %s", request);
}
}
Log Methods
The logger provides four log levels, each delegating to the corresponding console method:
Logger.error(String, Object...)→console.error()Logger.warn(String, Object...)→console.warn()Logger.info(String, Object...)→console.info()Logger.debug(String, Object...)→console.debug()
All log methods support string substitutions and accept a variable list of parameters for formatting.
Log Levels
The global log level is set using Logger.setLevel(Level). Override the level for a specific category with
Logger.setLevel(String, Level), or reset a category to the global level using Logger.resetLevel(String).
If a category contains ., it is interpreted hierarchically. For example, overriding org.jboss applies to all
subcategories like org.jboss.elemento (unless explicitly overridden otherwise).
Log Format
The log format is predefined as:
HH:mm:ss.SSS <level> [<category>] <message>and cannot be customized. Categories are trimmed and right-aligned. If the category is a fully qualified class name, package names are shortened (e.g.,
org.jboss.elemento.Logger becomes o.j.e.Logger).
JavaScript API
The logger exports methods to JavaScript (e.g., for use in browser dev tools) to control 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 when calling these methods from JavaScript!
Additional Features
The logger provides methods for:
- Grouping -
Logger.groupDebug(String, Object...),Logger.groupInfo(String, Object...),Logger.groupWarn(String, Object...),Logger.groupError(String, Object...),Logger.groupEnd() - Timers -
Logger.timeDebug(String),Logger.timeInfo(String),Logger.timeWarn(String),Logger.timeError(String),Logger.timeEnd(String) - Initialization from URL -
Logger.initFrom(elemental2.dom.Location)to set the global log level from a query parameter
- See Also:
-
ClassDescriptionLog levels supported by
LoggerSmall wrapper aroundconsole.logthat uses categories, log levels, and a predefined log format.