Logging

The 'logging' module provides a Logger type

Function Signatures


const LogLevels = {
    DEBUG: 0,
    INFO: 1,
    WARNING: 2,
    ERROR: 3,
    CRITICAL: 4
}

/*
    The Logger type returns a Logger object that can be configured to the user's needs.
    
    List of variables that the formatter understands and can replace at runtime:
    
    "%name%": Logger name
    %message%: Message
    %time%: Current time in ms
    %datetime%: Current date time
    %level%: Log level string
    %levelnum%: Log level number
    %baselevel%: Base log level string
    %baselevelnum%: Base log level number
    %format%: Provided format string
    %hh%: Current hour
    %mm%: Current minute
    %ss%: Current second
    %time%: Current time
    %day%: Current day
    %monthname%: Current month name
    %year%: Current year
    %dayname%: Current day name
*/

type Logger = (name: String = "root") => {
    // The name of the logger.
    name: String,
    // The base log level of the logger.
    baseLogLevel: Number,
    // The current log level of the logger.
    logLevel: Number,
    // The file path for logging.
    filePath: String,
    // The log message format.
    format: String,
    // An object to store custom log message formats.
    formatStore: Object,
    
    // Sets the name of the logger.
    setName: (name: String) => None,
    
    // Sets the base log level of the logger.
    setBaseLogLevel: (baseLogLevel: Number) => None,
    
    // Sets the file path for logging.
    setFilePath: (filePath: String) => None,
    
    // Sets the log message format.
    setFormat: (format: String) => None,
    
    // Adds a format key-value pair to the logger.
    addFormat: (key: String, value: Any) => None,
    
    // Logs a message at debug level.
    debug: (message: String) => None,
    
    // Logs a message at info level.
    info: (message: String) => None,
    
    // Logs a message at warning level.
    warn: (message: String) => None,
    
    // Logs a message at error level.
    error: (message: String) => None,
    
    // Logs a message at critical level.
    critical: (message: String) => None
}

Last updated