Static ReadonlyACTIONStatic constant (enum pattern) for log event types. Note: enum can't be defined inside a class, so we use a constant object.
CONTINUE means the script continues in case of error/warning log events.EXIT means the script throws a ScriptError in case of error/warning log events.Static ReadonlyLEVELStatic constant. It generates the same sequence as LOG_EVENT, but adding the zero case with OFF. It ensures the numeric values
match the values of LOG_EVENT. Note: enum can't be defined inside a class, so we use a constant object.
OFF means no log events will be sent to the appenders.ERROR means only error log events will be sent to the appenders.WARN means error and warning log events will be sent to the appenders.INFO means error, warning, and info log events will be sent to the appenders.TRACE means all log events (error, warning, info, trace) will be sent to the appenders.LOG_EVENT for the log event types used to determine the color of the message.
Adds an appender to the list of appenders.
The appender to add.
Sends an error log message (with optional structured extra fields) to all appenders if the level allows it.
The level has to be greater than or equal to LoggerImpl.LEVEL.ERROR to send this event to the appenders.
After the message is sent, it updates the error counter.
The error message to log.
OptionalextraFields: LogEventExtraFieldsOptional structured data to attach to the log event (e.g., context info, tags).
Serializes the current state of the logger to a plain object, useful for capturing logs and metrics for post-run analysis. For testing/debugging: Compare expected vs actual logger state. For persisting logs into Excel, JSON, or another external system.
A structure with key information about the logger, such as:
level, action, errorCount, warningCount, and criticalEvents.
Array with appenders subscribed to the Logger.
An array with error and warning event messages only sent to the appenders.
Returns the level of verbosity allowed in the Logger. The levels are incremental, i.e.
it includes all previous levels. For example: LoggerImpl.LEVEL.WARN includes warnings and errors since
LoggerImpl.LEVEL.ERROR is lower.
The current log level.
Sends an info log message (with optional structured extra fields) to all appenders if the level allows it.
The level has to be greater than or equal to LoggerImpl.LEVEL.INFO to send this event to the appenders.
The informational message to log.
OptionalextraFields: LogEventExtraFieldsOptional structured data to attach to the log event (e.g., context info, tags).
If the list of appenders is not empty, removes the appender from the list.
The appender to remove.
Sets the array of appenders with the input argument appenders.
Array with all appenders to set.
ScriptError If:
null or undefined, or contains null or undefined entries.Short version of the toString() which excludes the appenders details.
Similar to toString, but showing the list of appenders name only.
LoggerImpl.toString for more details.
Sends a trace log message (with optional structured extra fields) to all appenders if the level allows it.
The level has to be greater than or equal to LoggerImpl.LEVEL.TRACE to send this event to the appenders.
The trace message to log.
OptionalextraFields: LogEventExtraFieldsOptional structured data to attach to the log event (e.g., context info, tags).
Sends a warning log message (with optional structured extra fields) to all appenders if the level allows it.
The level has to be greater than or equal to LoggerImpl.LEVEL.WARN to send this event to the appenders.
After the message is sent, it updates the warning counter.
The warning message to log.
OptionalextraFields: LogEventExtraFieldsOptional structured data to attach to the log event (e.g., context info, tags).
StaticclearSets the singleton instance to null, useful for running different scenarios and testing purposes.
Mainly intended for testing purposes. The state of the singleton will be lost.
This method is available only in src folder, it is not deployed in dist folder (production).
It doesn't set the appenders to null, so the appenders are not cleared.
// Testing how the logger works with default configuration, and then changing the configuration.
// Since the class doesn't define setter methods to change the configuration, you can use
// clearInstance to reset the singleton and instantiate it with different configuration.
// Testing default configuration
let logger = LoggerImpl.getInstance() // LEVEL: WARN, ACTION: EXIT
logger.error("error event") // Output: "error event" and ScriptError
// Now we want to test with the following configuration: LoggerImpl.LEVEL:WARN, LoggerImpl.ACTION:CONTINUE
LoggerImpl.clearInstance() // Clear the singleton
logger = LoggerImpl.getInstance(LoggerImpl.LEVEL.WARN, LoggerImpl.ACTION.CONTINUE)
logger.error("error event") // Output: "error event" (no ScriptError was thrown)
StaticgetReturns the label for a log action value.
Optionalaction: 0 | 1The log action to get the label for.
The label for the action.
action is undefined, returns the label for the current logger instance's action.UNKNOWN.StaticgetReturns the singleton Logger instance, creating it if it doesn't exist.
If the Logger is created during this call, the provided level and action
parameters initialize the log level and error-handling behavior.
The verbosity level (default: LoggerImpl.LEVEL.WARN). Controls verbosity.
Sends events to the appenders up to the defined level of verbosity.
The level of verbosity is incremental, except for value
LoggerImpl.LEVEL.OFF, which suppresses all messages sent to the appenders.
For example: LoggerImpl.LEVEL.INFO allows sending errors, warnings, and information events,
but excludes trace events.
The action on error/warning (default: LoggerImpl.ACTION.EXIT).
Determines if the script should continue or abort.
If the value is LoggerImpl.ACTION.EXIT, throws a ScriptError exception,
i.e. aborts the Script. If the action is LoggerImpl.ACTION.CONTINUE, the
script continues. It only takes effect if the level is not LoggerImpl.LEVEL.OFF.
The singleton Logger instance.
ScriptError If:
LoggerImpl.LEVEL or it doesn't
match the LOG_EVENT enum values in the specified order.LoggerImpl.ACTION.// Initialize logger at INFO level, continue on errors/warnings
const logger = Logger.getInstance(LoggerImpl.LEVEL.INFO, LoggerImpl.ACTION.CONTINUE)
// Subsequent calls ignore parameters, return the same instance
const sameLogger = Logger.getInstance(LoggerImpl.LEVEL.ERROR, LoggerImpl.ACTION.EXIT)
logger.info("Starting the Script") // Send this message to all appenders
logger.trace("Step one")           // Doesn't send because of LoggerImpl.LEVEL value: INFO
StaticgetReturns the label for the given log level.
Optionallevel: numberThe label for the log level.
level is undefined, returns the label for the current logger instance's level.UNKNOWN.
Singleton class that manages application logging through appenders.
ERROR,WARN,INFO,TRACE(LOG_EVENTenum).LoggerImpl.LEVEL:OFF,ERROR,WARN,INFO,TRACE, whereWARNis the default maximum level of verbosity.LEVEL) isOFF, no log events will be sent to the appenders.ERROR,WARNlog events: the script can continue (LoggerImpl.ACTION.CONTINUE), or abort (LoggerImpl.ACTION.EXITdefault). Such actions only take effect if theLEVELis notLoggerImpl.LEVEL.OFF.getCriticalEvents().Usage:
LoggerImpl.getInstance(level, action).ConsoleAppender,ExcelAppender), viaaddAppender()for example.logger.error(),logger.warn(),logger.info(), orlogger.trace()to log.Features:
logger.error()) if the singleton was not instantiated, it does a lazy initialization of the logger with default configuration, i.e.LoggerImpl.LEVEL=WARNandLoggerImpl.ACTION=EXIT.ConsoleAppenderis used by default.LoggerImplwill automatically create and add aConsoleAppender. This ensures that log messages are not silently dropped. You may replace or remove this appender at any time usingsetAppenders()orremoveAppender().Example
See