Class LoggingService
It also manages all custom logging events, appenders and loggers.
It's not a true BoxLang service, due to the chicken and egg problem of logging being needed before the runtime starts.
The configureBasic(Boolean) method is called by the runtime to setup the basic logging system first, then
once the runtime is online and has read the configuration file (boxlang.json), it can reconfigure the logging system
via the reconfigure() method.
Please note that in BoxLang you can use the following arguments for logging via the logMessage(String, String, String, String) method:
- message - The message to send for logging or a lambda that produces the message
- type - The logging level type (error, info, warn, debug, trace)
- applicationName - The name of the BoxLang application (if any)
- logger - The named logger to emit to. Example: "scheduler, application, orm, etc"
If the named logger does not exist or it's an absolute path, then the logger will be registered as a new logger, with the name of the file as the category.
-
Field Summary
FieldsModifier and TypeFieldDescription-------------------------------------------------------------------------- Public Common Loggers -------------------------------------------------------------------------- These are the common loggers that are used in the runtime, loaded by default so they are fast to use.static final Stringstatic final Stringstatic final Stringstatic Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String-------------------------------------------------------------------------- Public Constants --------------------------------------------------------------------------static final Stringstatic final StringThe log format for the BoxLang runtime -
Method Summary
Modifier and TypeMethodDescriptionconfigureBasic(Boolean debugMode) This configures LogBack with a basic configuration, so we can use logging before we actually read the configuration file.Get a list of all registered file appendersch.qos.logback.core.encoder.EncoderBase<ch.qos.logback.classic.spi.ILoggingEvent> Get the BoxLang pattern encoderch.qos.logback.core.encoder.EncoderBase<ch.qos.logback.classic.spi.ILoggingEvent> getEncoderForLoggerConfig(LoggerConfig loggerConfig) This method receives a logger config and returns the encoder to useAlias to get the exception loggerstatic LoggingServiceGet the singleton instance of the LoggingServicestatic LoggingServicegetInstance(BoxRuntime runtime) Get the singleton instance of the LoggingService and initializing it with the runtime This is called by the Runtime only!Get a logger by registered name.ch.qos.logback.classic.LoggerContextGet the logger contextintTell me how many loggers have been registeredGet a list of all the registered loggers so far in the runtimeGet a list of all the registered loggers so far in the runtimeGet the runtime's log directory as per the configurationch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> getOrBuildAppender(String filePath, ch.qos.logback.classic.LoggerContext logContext, LoggerConfig loggerConfig) Get the requested file appender according to log locationGet the root loggerAlias to get the runtime loggerbooleanhasAppender(String filePath) Verify if we have the passed in filePath appenderbooleanVerify if a logger with the specified name existslogMessage(String message) Log a message into the default log file and the default log type with no application namelogMessage(String message, String type) Log a message into the default log file and a custom log type with no application namelogMessage(String message, String type, String applicationName) Log a message into the default log file and a custom log type and a custom application namelogMessage(String message, String type, String applicationName, String logger) Log a message with specific argumentsThis method is called by the runtime to reconfigure the logging system once the configuration file has been read.booleanremoveAppender(String filePath) Remove the appender from the cache using the file pathbooleanremoveLogger(Key loggerName) Remove a logger by namesetDefaultEncoder(ch.qos.logback.core.encoder.EncoderBase<ch.qos.logback.classic.spi.ILoggingEvent> encoder) Store the BoxLang pattern encodersetLoggerContext(ch.qos.logback.classic.LoggerContext loggerContext) Set the logger contextsetRootLogger(BoxLangLogger logger) Set the root logger for the runtimeshutdown()Shutdown the logging serviceShutdown all the appenders
-
Field Details
-
LEVEL_TRACE
-------------------------------------------------------------------------- Public Constants --------------------------------------------------------------------------- See Also:
-
LEVEL_DEBUG
- See Also:
-
LEVEL_INFO
- See Also:
-
LEVEL_WARN
- See Also:
-
LEVEL_ERROR
- See Also:
-
LEVEL_FATAL
- See Also:
-
DEFAULT_LOG_TYPE
- See Also:
-
DEFAULT_LOG_FILE
- See Also:
-
DEFAULT_APPLICATION
- See Also:
-
CONTEXT_NAME
- See Also:
-
DEFAULT_LOG_LEVEL
-
APPLICATION_LOGGER
-------------------------------------------------------------------------- Public Common Loggers -------------------------------------------------------------------------- These are the common loggers that are used in the runtime, loaded by default so they are fast to use. -
ASYNC_LOGGER
-
CACHE_LOGGER
-
EXCEPTION_LOGGER
-
DATASOURCE_LOGGER
-
MODULES_LOGGER
-
RUNTIME_LOGGER
-
SCHEDULER_LOGGER
-
LOG_FORMAT
The log format for the BoxLang runtime- See Also:
-
-
Method Details
-
getInstance
Get the singleton instance of the LoggingService and initializing it with the runtime This is called by the Runtime only!- Returns:
- The LoggingService instance
-
getInstance
Get the singleton instance of the LoggingService- Returns:
- The LoggingService instance
- Throws:
IllegalStateException- If the LoggingService has not been initialized yet
-
getRootLogger
Get the root logger- Returns:
- The root logger
-
getLogsDirectory
Get the runtime's log directory as per the configuration -
setRootLogger
Set the root logger for the runtime- Parameters:
logger- The logger to set- Returns:
- The logging service
-
getDefaultEncoder
public ch.qos.logback.core.encoder.EncoderBase<ch.qos.logback.classic.spi.ILoggingEvent> getDefaultEncoder()Get the BoxLang pattern encoder- Returns:
- The encoder
-
getEncoderForLoggerConfig
public ch.qos.logback.core.encoder.EncoderBase<ch.qos.logback.classic.spi.ILoggingEvent> getEncoderForLoggerConfig(LoggerConfig loggerConfig) This method receives a logger config and returns the encoder to use- Parameters:
loggerConfig- The logger configuration to use- Returns:
- The encoder to use for the logger configuration
-
setDefaultEncoder
public LoggingService setDefaultEncoder(ch.qos.logback.core.encoder.EncoderBase<ch.qos.logback.classic.spi.ILoggingEvent> encoder) Store the BoxLang pattern encoder- Parameters:
encoder- The encoder to store- Returns:
- LoggingService
-
getLoggerContext
public ch.qos.logback.classic.LoggerContext getLoggerContext()Get the logger context- Returns:
- The logger context
-
setLoggerContext
Set the logger context- Parameters:
loggerContext- The logger context to set- Returns:
- The logging service
-
configureBasic
This configures LogBack with a basic configuration, so we can use logging before we actually read the configuration file.Once the configuration file is read, we can reconfigure the logging system.
- Parameters:
debugMode- The flag the runtime was started with
-
reconfigure
This method is called by the runtime to reconfigure the logging system once the configuration file has been read.This could change logging levels, add new appenders, etc.
-
logMessage
Log a message into the default log file and the default log type with no application name- Parameters:
message- The message to log- Returns:
- The logging service
-
logMessage
Log a message into the default log file and a custom log type with no application name- Parameters:
message- The message to logtype- The type of log message (fatal, error, info, warn, debug, trace)- Returns:
- The logging service
-
logMessage
Log a message into the default log file and a custom log type and a custom application name- Parameters:
message- The message to logtype- The type of log message (fatal, error, info, warn, debug, trace)applicationName- The name of the application requesting the log message- Returns:
- The logging service
-
logMessage
public LoggingService logMessage(String message, String type, String applicationName, String logger) Log a message with specific arguments- Parameters:
message- The message to logtype- The type of log message (fatal, error, info, warn, debug, trace)applicationName- The name of the application requesting the log messagelogger- The logger destination. It can be a named logger or an absolute path- Returns:
- The logging service
- Throws:
IllegalArgumentException- If the log level is not valid
-
getRuntimeLogger
Alias to get the runtime logger- Returns:
- The runtime logger
-
getExceptionLogger
Alias to get the exception logger -
getLogger
Get a logger by registered name. If the logger doesn't exist, it will auto-register it and load it using the name as the file name in the logs directory.- Parameters:
logger- The name of the logger to retrieve.- Returns:
- The logger requested
-
hasLogger
Verify if a logger with the specified name exists- Parameters:
loggerName- The name of the logger to verify
-
getLoggersCount
public int getLoggersCount()Tell me how many loggers have been registered- Returns:
- The number of loggers registered
-
getLoggersList
Get a list of all the registered loggers so far in the runtime- Returns:
- The list of loggers
-
getLoggersKeys
Get a list of all the registered loggers so far in the runtime- Returns:
- The list of loggers
-
removeLogger
Remove a logger by name- Parameters:
loggerName- The name of the logger to remove- Returns:
- True if the logger was removed, false otherwise
-
getOrBuildAppender
public ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> getOrBuildAppender(String filePath, ch.qos.logback.classic.LoggerContext logContext, LoggerConfig loggerConfig) Get the requested file appender according to log location- Parameters:
filePath- The file path to get the appender forlogContext- The logger context requested for the appenderloggerConfig- The logger configuration- Returns:
- The appender for the requested logger configuration
-
hasAppender
Verify if we have the passed in filePath appender- Returns:
- True if the appender exists, false otherwise
-
removeAppender
Remove the appender from the cache using the file path- Parameters:
filePath- The file path to remove the appender for- Returns:
- True if the appender was removed, false otherwise
-
getAppendersList
Get a list of all registered file appenders- Returns:
- The list of appenders
-
shutdownAppenders
Shutdown all the appenders- Returns:
- The logging service
-
shutdown
Shutdown the logging service
-