rhodonite
    Preparing search index...

    Class Logger

    A comprehensive logging utility class that provides various log levels, message formatting, and log accumulation capabilities.

    Features:

    • Multiple log levels (Debug, Info, Warn, Error, Assert)
    • Rich formatting with timestamps
    • Log accumulation for later retrieval
    • Configurable log level filtering
    // Create logger instance
    const logger = new Logger();
    logger.logLevel = LogLevel.Info;
    logger.isRichLog = true;
    logger.isAccumulateLog = true;

    // Use logging methods
    logger.info("Application started");
    logger.warn("This is a warning");
    logger.error("An error occurred");

    // Retrieve accumulated logs
    const logs = logger.getAccumulatedLog();
    Index

    Constructors

    Properties

    isAccumulateLog: boolean = false

    Whether to store log messages in memory for later retrieval.

    isRichLog: boolean = false

    Whether to format log messages with timestamps and log level prefixes.

    logLevel: LogLevel = LogLevel.Warn

    The minimum log level that will be output. Messages below this level are ignored.

    default: Logger = ...

    The default global Logger instance for code that doesn't have access to an Engine.

    Methods

    • Performs a console assertion and logs a message if the condition is false. Assert messages are used for debugging and testing critical assumptions.

      Parameters

      • condition: boolean

        The condition to test; if false, the assertion fails

      • message: string

        The message to log when the assertion fails

      Returns string | undefined

      The formatted message if logged, undefined if filtered out

      logger.assert(user !== null, "User object should not be null at this point");
      
    • Logs a debug message to the console if the current log level permits it. Debug messages provide detailed information useful for troubleshooting and development.

      Parameters

      • message: string

        The debug message to log

      Returns string | undefined

      The formatted message if logged, undefined if filtered out

      logger.debug("Processing user input: " + JSON.stringify(input));
      
    • Logs an error message to the console if the current log level permits it. Error messages indicate serious problems that should be addressed immediately.

      Parameters

      • message: string

        The error message to log

      Returns string | undefined

      The formatted message if logged, undefined if filtered out

      logger.error("Database connection failed");
      
    • Retrieves all accumulated log messages as formatted strings. Only available when isAccumulateLog is enabled.

      Returns string[]

      An array of formatted log message strings

      logger.isAccumulateLog = true;
      logger.info("First message");
      logger.warn("Second message");

      const logs = logger.getAccumulatedLog();
      console.log(logs); // Array of formatted log messages
    • Logs an informational message to the console if the current log level permits it. Info messages provide general information about application flow and state.

      Parameters

      • message: string

        The informational message to log

      Returns string | undefined

      The formatted message if logged, undefined if filtered out

      logger.info("User authentication successful");
      
    • Logs a warning message to the console if the current log level permits it. Warning messages indicate potential issues that should be monitored.

      Parameters

      • message: string

        The warning message to log

      Returns string | undefined

      The formatted message if logged, undefined if filtered out

      logger.warn("API response time is slower than expected");