AbstractProtectedconstructorConstructs a new AbstractAppender instance. Nothing is initialized, because the class only has static properties
that are lazy initialized or set by the user.
StaticdefaultDefault factory function to create LogEvent instances. Used in case it was not set before by the user.
ProtectedclearTo ensure when invoking clearInstance method in a sub-class it also clears (null) the last log event
sent to the appender.
The last log event sent by the appender.
Log a LogEvent or build a log event using a message string with event type, and if present, with extra fields.
It implements both the log methods from the Appender interface,
since in Typescript doesn't allow you to overload methods with the same name but with different signatures.
LogEvent or message string.
Optionalarg2: LOG_EVENTLOG_EVENT type. Only required if arg1 is a string.
Optionalarg3: LogEventExtraFieldsextraFields, only used if arg1 is a string.
ScriptError if:
arg1 is a string but arg2 is not provided or is not a valid LOG_EVENT.arg1 is not a string and arg1 is not a valid LogEvent.arg1 is a string, it creates a new LogEvent using the provided message and event type, and if presents extraFields.arg1 is already a LogEvent, it validates the event and sends it directly.arg3 parameter is optional and can be used to provide extra fields to create a log event, if arg1 is a string.sendEvent abstract method. Therefore subclasses must implement the sendEvent method to define how the log event is sent.// Example: Log an error message with a custom event type and extra fields.
const appender = new ConsoleAppender() // Assuming ConsoleAppender extends AbstractAppender
appender.log("An error occurred", LOG_EVENT.ERROR, { user: "dlealv", id: 42 })
// Example: Log a warning event directly.
const warningEvent = new LogEventImpl("This is a warning", LOG_EVENT.WARNING)
appender.log(warningEvent) // Directly log a LogEvent instance
Protected AbstractsendSend the log event to the appropriate destination. This method must be implemented by subclasses to define how the log event is sent. It is the final responsible for sending the log event to the appropriate destination (e.g., console, file, etc.).
The log event to be sent.
Optionalcontext: string(Optional) A string to provide additional context in case of an error.
ProtectedsetSet the last log event sent to the appender.
The log event to be sent.
Returns a string representation of the appender. It includes the class name, layout, log event factory, so far this class doesn't have additional properties to show. Intended to be used by subclasses to provide information of the base class.
A string representation of the appender.
StaticclearStaticclearStaticgetThe layout associated to all events. Used to format the log event before sending it to the appenders. If the layout was not set, it returns a default layout (lazy initialization). The layout is shared by all events and all appenders, so it is static.
StaticgetGets the log event factory function used to create LogEvent instances. If it was not set before, it returns the default factory function.
The logEventFactory is shared by all events and all appenders, so it is static.
The log event factory function.
StaticsetSets the layout associated to all events, the layout is assigned only if it was not set before.
The layout to set.
StaticsetSets the log event factory function used to create LogEvent instances if it was not set before.
A factory function to create LogEvent instances.
Must have the signature (message: string, eventType: LOG_EVENT) => LogEvent, i.e. LogEventFactory type.
If not provided, a default factory function is used.
// Example: Custom LogEvent to be used to specify the environment where the log event was created.
let prodLogEventFactory: LogEventFactory
   = function prodLogEventFactoryFun(message: string, eventType: LOG_EVENT) {
     return new LogEventImpl("PROD-" + message, eventType) // add environment prefix
   }
AbstractAppender.setLogEventFactory(prodLogEventFactory) // Now all appenders will use ProdLogEvent
Abstract base class for all log appenders. Provides a common interface and shared functionality for concrete appender implementations.
Features:
Layout(see Layout).LogEventFactoryfunction type to create log events, enabling flexible and customizable event creation.sendEventmethod.Usage:
ConsoleAppender,ExcelAppender).sendEvent(event, context)method to define how log events are delivered.Remarks
See