JSLogger

Overview

The JSLogger class provides a comprehensive API for managing logging operations. It supports constructing log events with various severity levels, such as fatal, error, warn, info, debug, and trace, using the JSLogBuilder instances it creates. Logs can include messages formatted with arguments, enabling flexible and detailed logging. The class offers methods to check if a specific logging level is enabled, allowing efficient logging decisions. It also allows dynamically setting the logger's logging level, overriding the default configuration. This global change persists until the application server is restarted. The current logging level can be retrieved as a string using the level property.

Properties Summarized

Type
Name
Summary

Construct a log event that will always be logged.

Construct a debug log event.

Check if the current logger's logging level enables logging on the debug level.

Construct an error log event.

Check if the current logger's logging level enables logging on the error level.

Construct a fatal log event.

Check if the current logger's logging level enables logging on the fatal level.

Construct an info log event.

Check if the current logger's logging level enables logging on the info level.

Get the logging level of this logger

Construct a trace log event.

Check if the current logger's logging level enables logging on the trace level.

Construct a warn log event.

Check if the current logger's logging level enables logging on the warn level.

Methods Summarized

Type
Name
Summary

void

Set the level for this logger.

Properties Detailed

always

Construct a log event that will always be logged.

Type JSLogBuilder a LogBuilder

Sample

var log = application.getLogger();
log.always.log("some message and {} {}", "some", "arguments");

debug

Construct a debug log event.

Type JSLogBuilder a LogBuilder

Sample

var log = application.getLogger();
log.debug.log("some message and {} {}", "some", "arguments");

debugEnabled

Check if the current logger's logging level enables logging on the debug level. Return true if the logger's level is set to debug or trace.

Type Boolean true if 'debug' level is enabled for logging

error

Construct an error log event.

Type JSLogBuilder a LogBuilder

Sample

var log = application.getLogger();
log.error.log("some message and {} {}", "some", "arguments");

errorEnabled

Check if the current logger's logging level enables logging on the error level. Return true if the logger's level is set to error, warn, info, debug or trace.

Type Boolean true if 'error' level is enabled for logging

fatal

Construct a fatal log event.

Type JSLogBuilder a LogBuilder

Sample

var log = application.getLogger();
log.fatal.log("some message and {} {}", "some", "arguments");

fatalEnabled

Check if the current logger's logging level enables logging on the fatal level. Return true if the logger's level is set to fatal, error, warn, info, debug or trace.

Type Boolean true if 'fatal' level is enabled for logging

info

Construct an info log event.

Type JSLogBuilder a LogBuilder

Sample

var log = application.getLogger();
log.info.log("some message and {} {}", "some", "arguments");

infoEnabled

Check if the current logger's logging level enables logging on the info level. Return true if the logger's level is set to info, debug or trace.

Type Boolean true if 'info' level is enabled for logging

level

Get the logging level of this logger

Type String the logging level of this logger

trace

Construct a trace log event.

Type JSLogBuilder a LogBuilder

Sample

var log = application.getLogger();
log.trace.log("some message and {} {}", "some", "arguments");

traceEnabled

Check if the current logger's logging level enables logging on the trace level. Return true if the logger's level is set to trace.

Type Boolean true if 'trace' level is enabled for logging

warn

Construct a warn log event.

Type JSLogBuilder a LogBuilder

Sample

var log = application.getLogger();
log.warn.log("some message and {} {}", "some", "arguments");

warnEnabled

Check if the current logger's logging level enables logging on the warn level. Return true if the logger's level is set to warn, info, debug or trace.

Type Boolean true if 'warn' level is enabled for logging

Methods Detailed

setLevel(level)

Set the level for this logger. Be aware that this will override the logging level as configured in log4j.xml, meaning it affects all JSLogger instances based on that configuration. This changes the global configuration, meaning that restarting the client will not reset the logging level to it's default state. Only restarting the application server will reset the logging level to it's default state.

Parameters

  • JSLogBuilder level the desired logging level for this logger

Returns: void

Sample

var log = application.getLogger("myLogger");
log.setLevel(log.info);

Last updated

Was this helpful?