officescripts-logging-framework
    Preparing search index...

    Class LogEventImpl

    Implements the LogEvent interface, providing a concrete representation of a log event. It includes properties for the event type, message, timestamp and additional extra fields, along with validation methods.

    • This class is immutable after construction, ensuring that all properties are set at creation time.
    • It validates the input parameters to ensure they conform to expected types and constraints.
    • The extraFields property allows for extensibility, enabling additional metadata to be attached to log events.
    • The toString() method provides a standardized string representation of the log event.
    • LogEvent for the interface definition.
    • LOG_EVENT for the enumeration of log event types.

    Implements

    Index

    Constructors

    • Constructs a new LogEventImpl instance. Validates the input parameters to ensure they conform to expected types and constraints.

      Parameters

      • message: string

        The message to log.

      • type: LOG_EVENT

        The type of the log event (from LOG_EVENT enum).

      • OptionalextraFields: LogEventExtraFields

        (Optional) Additional fields for the log event, can include strings, numbers, dates, or functions.

      • timestamp: Date = ...

        (Optional) The timestamp of the event, defaults to current time.

      Returns LogEventImpl

      ScriptError if validation fails:

      • type is not a valid LOG_EVENT enum value.
      • message is not a non-empty string.
      • timestamp is not a valid Date.
      • extraFields is not a plain object or contains reserved keys.
      • This class is immutable after construction, ensuring that all properties are set at creation time.
      • It validates the input parameters to ensure they conform to expected types and constraints.
      • The extraFields property allows for extensibility, enabling additional metadata to be attached to log events.

    Accessors

    • get extraFields(): Readonly<LogEventExtraFields>

      Gets the extra fields of the log event.

      Returns Readonly<LogEventExtraFields>

      Returns a shallow copy of custom fields for this event. These are immutable (Object.freeze), but if you allow object values in the future, document that deep mutation is not prevented.

    Methods

    • Returns a standardized label for the given log event.

      Parameters

      • type: LOG_EVENT

        The event type from LOG_EVENT enum.

      Returns string

      A string label, e.g., [INFO], [ERROR].

      ScriptError if the type is not a valid LOG_EVENT enum value.

    • Validates if the input object conforms to the LogEvent interface (for any implementation).

      Parameters

      • event: unknown
      • Optionalcontext: string

      Returns void

      ScriptError if log event is invalid.