Class Logger

java.lang.Object
org.jboss.elemento.logger.Logger

public class Logger extends Object
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:

  1. error(String, Object...) → console.error()
  2. warn(String, Object...) → console.warn()
  3. info(String, Object...) → console.info()
  4. 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 level
  • org.jboss.elemento.logger.Logger.setLevel(String category, String level) - overrides the log level for one category
  • org.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!
See Also:
  • Field Details

  • Method Details

    • initFrom

      public static void initFrom(Location location)
      Sets the global log level from the "log-level" query parameter. If no query parameter was given, this method does nothing.
    • initFrom

      public static void initFrom(Location location, String queryParameter)
      Sets the global log level from the specified query parameter. If no query parameter was given, this method does nothing.
    • getLogger

      public static Logger getLogger(String category)
      Retrieves or creates a logger with the specified category.
      Parameters:
      category - the category of the logger
      Returns:
      the logger instance
    • setLevel

      public static void setLevel(Level level)
      Sets the global log level.
      Parameters:
      level - the desired log level to be set
    • setLevel

      public static void setLevel(String category, Level level)
      Sets the log level for a given category.
      Parameters:
      category - the category for which to set the log level
      level - the log level to be set
    • resetLevel

      @JsMethod public static void resetLevel(String category)
      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

      public void debug(String message, Object... params)
    • info

      public void info(String message, Object... params)
    • warn

      public void warn(String message, Object... params)
    • error

      public void error(String message, Object... params)
    • isEnabled

      public boolean isEnabled(Level level)
    • groupDebug

      public void groupDebug(String message, Object... params)
    • groupInfo

      public void groupInfo(String message, Object... params)
    • groupWarn

      public void groupWarn(String message, Object... params)
    • groupError

      public void groupError(String message, Object... params)
    • groupEnd

      public void groupEnd()
    • timeDebug

      public String timeDebug(String message)
    • timeDebugLog

      public void timeDebugLog(String timer, Object... params)
    • timeInfo

      public String timeInfo(String message)
    • timeInfoLog

      public void timeInfoLog(String timer, Object... params)
    • timeWarn

      public String timeWarn(String message)
    • timeWarnLog

      public void timeWarnLog(String timer, Object... params)
    • timeError

      public String timeError(String message)
    • timeErrorLog

      public void timeErrorLog(String timer, Object... params)
    • timeEnd

      public void timeEnd(String timer)