Module jls.lang.logger

Returns the default logger implementation.

A Logger object is used to record events during the execution of Lua modules. This default implementation provides a simple way for module owner to expose debugging information and for module user to access this information. This default implementation could be configured to redirect log messages to another logging facility.

The default log level is warning. The default formatting consists in prefixing the message by the date time as ISO 8601, the module name and the log level. The default writing consists in printing the log message to the standard error stream, adding a new line and flushing.

The JLS_LOGGER_LEVEL environment variable could be used to indicate the log level to use. You could use comma separated values of module name and associated level, "INFO,jls.net:FINE".

Usage:

    local logger = require('jls.lang.logger'):get(...) -- require will pass the module name
    logger:info('Some usefull information message')
    
    if logger:isLoggable(logger.FINE) then
      logger:fine('Some fine message')
    end
    

Tables

LEVEL The available log levels.

Class Logger

Logger:new ([name[, level]]) Creates a new logger with the specified level.
logger:get ([name]) Returns the logger for the specified name.
logger:getLevel () Returns the log level for this logger.
logger:setLevel (level) Sets the log level for this logger.
logger:isLoggable (level) Tells wether or not a message of the specified level will be logged by this logger.
logger:log (level, message) Logs the specified message with the specified level.
logger:error (message) Logs the specified message with the ERROR level.
logger:warn (message) Logs the specified message with the WARN level.
logger:info (message) Logs the specified message with the INFO level.
logger:config (message) Logs the specified message with the CONFIG level.
logger:debug (message) Logs the specified message with the DEBUG level.
logger:fine (message) Logs the specified message with the FINE level.
logger:finer (message) Logs the specified message with the FINER level.
logger:finest (message) Logs the specified message with the FINEST level.
logger:setConfig (config) Sets the specified logger level configuration.
logger:getConfig () Returns the logger level configuration.


Tables

LEVEL
The available log levels. The level fields are also provided as shortcut to the default implementation.

Fields:

  • ERROR The error level is the highest level
  • WARN The warning level
  • INFO The information level
  • CONFIG The configuration level
  • FINE The fine level
  • FINER The finer level
  • FINEST The finest level
  • DEBUG The debug level Do not use, shall be removed
  • ALL The all level is the lowest level

Class Logger

A Logger class. A Logger object is used to log messages for a specific system or application component.
Logger:new ([name[, level]])
Creates a new logger with the specified level.

Parameters:

  • name string The module name (optional)
  • level The log level (optional)

Returns:

    a new logger

Usage:

    local console = require('jls.lang.logger'):getClass():new()
    console:info('Some usefull information message')
logger:get ([name])
Returns the logger for the specified name. The returned logger inherits from this logger configuration.

Parameters:

  • name string The module name (optional)

Returns:

    a logger

Usage:

    local console = require('jls.lang.logger'):get(...)
    console:info('Some usefull information message')
logger:getLevel ()
Returns the log level for this logger.

Returns:

    number the log level for this logger.
logger:setLevel (level)
Sets the log level for this logger.

Parameters:

  • level The log level.
logger:isLoggable (level)
Tells wether or not a message of the specified level will be logged by this logger.

Parameters:

  • level number The log level to check.

Returns:

    boolean true if a message of the specified level will be logged by this logger.
logger:log (level, message)
Logs the specified message with the specified level. When the message is a string then additional arguments are formatted using string.format. The specifier t or T stringifies the table argument. The specifier l formats a string or a table argument to its size. The specifier x or X formats a string argument to hexadecimal.

Parameters:

  • level The log level.
  • message The log message.
logger:error (message)
Logs the specified message with the ERROR level.

Parameters:

  • message The log message.
logger:warn (message)
Logs the specified message with the WARN level.

Parameters:

  • message The log message.
logger:info (message)
Logs the specified message with the INFO level.

Parameters:

  • message The log message.
logger:config (message)
Logs the specified message with the CONFIG level.

Parameters:

  • message The log message.
logger:debug (message)
Logs the specified message with the DEBUG level.

Parameters:

  • message The log message.
logger:fine (message)
Logs the specified message with the FINE level.

Parameters:

  • message The log message.
logger:finer (message)
Logs the specified message with the FINER level.

Parameters:

  • message The log message.
logger:finest (message)
Logs the specified message with the FINEST level.

Parameters:

  • message The log message.
logger:setConfig (config)
Sets the specified logger level configuration. The configuration is a list of comma separated values of module name and associated level. The configuration is applied in the specified order on this logger and all its sub loggers.

Parameters:

  • config string The log configuration.
logger:getConfig ()
Returns the logger level configuration.

Returns:

    string the configuration
generated by LDoc 1.4.6