diff --git a/CHANGELOG.md b/CHANGELOG.md index 092c689..7a7629c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [2.1.4] – 2025-07-17 +### Changed +- Reviewed, in details, the TYPEDOC documentation, corrected some examples and added more details. + ## [2.1.3] – 2025-07-15 ### Changed - Updated `README.md` with minor corrections about extra field output diff --git a/docs/typedoc/assets/highlight.css b/docs/typedoc/assets/highlight.css index 61c405b..6febc3d 100644 --- a/docs/typedoc/assets/highlight.css +++ b/docs/typedoc/assets/highlight.css @@ -23,8 +23,6 @@ --dark-hl-10: #C8C8C8; --light-hl-11: #000000FF; --dark-hl-11: #D4D4D4; - --light-hl-12: #CD3131; - --dark-hl-12: #F44747; --light-code-background: #FFFFFF; --dark-code-background: #1E1E1E; } @@ -42,7 +40,6 @@ --hl-9: var(--light-hl-9); --hl-10: var(--light-hl-10); --hl-11: var(--light-hl-11); - --hl-12: var(--light-hl-12); --code-background: var(--light-code-background); } } @@ -59,7 +56,6 @@ --hl-9: var(--dark-hl-9); --hl-10: var(--dark-hl-10); --hl-11: var(--dark-hl-11); - --hl-12: var(--dark-hl-12); --code-background: var(--dark-code-background); } } @@ -76,7 +72,6 @@ --hl-9: var(--light-hl-9); --hl-10: var(--light-hl-10); --hl-11: var(--light-hl-11); - --hl-12: var(--light-hl-12); --code-background: var(--light-code-background); } @@ -93,7 +88,6 @@ --hl-9: var(--dark-hl-9); --hl-10: var(--dark-hl-10); --hl-11: var(--dark-hl-11); - --hl-12: var(--dark-hl-12); --code-background: var(--dark-code-background); } @@ -109,5 +103,4 @@ .hl-9 { color: var(--hl-9); } .hl-10 { color: var(--hl-10); } .hl-11 { color: var(--hl-11); } -.hl-12 { color: var(--hl-12); } pre, code { background: var(--code-background); } diff --git a/docs/typedoc/assets/search.js b/docs/typedoc/assets/search.js index eabe3ce..3e9fa75 100644 --- a/docs/typedoc/assets/search.js +++ b/docs/typedoc/assets/search.js @@ -1 +1 @@ -window.searchData = "eJy1nd9v2zgSx/+Vg/rqzXpEUj/yFvTSQ4FcC7Td3QejKLyO4hjn2IGktFsU/d8PpCh7SA6lke0+dRFrZijyw+HwS0n7I6n335rkevEj+d9md59cF7Nkt3yqkuvk7v1/vtz+efvuUzJLXuptcp1Uu5en5vfD368e26dtMktW22XTVE1ynSQ/Z70fyA6Obj98eP9h0Mmrqq73tetqljwv62rXOi0h/b999+b9sPvN7mF/qvdPH25e3w67b+vlqjrV/183H94Nu/+2rHfTvKfHUbz5u9HNa2+en6vdfVUfQll3v/sXDI6qgvTgebXfNW39smr3TKevXItjgLa5/23T/PZc79tq1Vb3+P6C9qPbnKfy0Jr76mH5sm3v9uvbr9WufbPUUb6/edkx22btt/t1pe0fOvuHl3jPD7QsncvjCKy21bK+WzaHtnF7S9ttl82hTZfoM6dl66o9oV3rqo226pRWbPdrZuTuyvOiNdXufsrd6ut/Te83J/V+M9D7l2hVu//Y1psdd0jafdNffpFZ8n3/MnF+WItLRHdzx6RmuGnj7PaYmTmhL8ycvEhP6Mgn9YNuwoV7oZnYC83FeqE5tReai/QCXsBf73fNfltF12/v9+Gi7LQVkwrBXDBtStrsHqt646Uk/85OXj/J9k1bPv91gYaOLadkM4dW0wu0iVpcyXb4a+sFYseXWrIF01dadjtOGJcp6+wl4Imuu2TrRpfdKXPr7a5plzuzg+HOq83R5Pz4kRw/NKuDJH+xPDOS9QcaNZD2L5Ncpo3TumovNUrxaiSe0n7FCDFqk2iDfu3oxCuVeHL5FT3EqFuiDbp4D+Eq5vafVbWN1jDOr/wK5t+3b27+uPvU6R9f3rx/9+kjw3VfuXwxt/vlYb9rm+gMcdt9diUVb80ZdVSsjROrKKJtF6yhWI1cV23Xg3ZMRhu4rtqu104axEnVGx39pNqN257/NuvX1Xb7gagK6NY8NetVtd3WA4UBKzZVNRIRp9SMrLjxipGIPr1eZLZhMgcXqxVZDYxWikTLRutEfu6IVh+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XHt3tcxz3b/kgh2jlKfrkLnjlt/MuD3KJSo6iX3AFL8N3L+6gEUEVXGdS9Isac510X65HYOJJNOdN+XAqZmiqA/C6rfNCJrgc7zskb1g7dxvzGT3UcWiaKF7fBwlBIjZypo+9M6FgjjvZpkI7H2SfYoA3L7b79Zcg0yL/vPWAStc5biXwFvveT6RmygUeSCYX8aSXO1sx9lAYdz4ZAvnK2C1be6Di2jplgmq8+M2RyFPOc3R4tx3dFN6h9TkHeOuN/w4fymSodCn60pK5i7Lv6yFnqIllXwYytzb0J2JQGsK4zXm92JhvuwSbpgyP7Jw3qdD/dgHNfezIlj2pXbKYM6KJVNQKJbeyr6iYYkfwP2ZALcbZ1y43qV0TmZOuIes1LEnZ5UvYLKiYgzVcE+FVyHIqbFcrZleHnwRHiwnyr3jEoo9CoFmKxi07bE55jHmfdkMwoN4teUvJ8cVT1Id4CtmlKbWZRPZiTy8j9DuFfgmb9zUeHBa1g5TZ76OYex/7wirqNLRTsWH7aJJXnHcfzkAeUY9lhx0zz9dL/70nlDHw4jTnzRPi2+WofWgeZrwR9T9Ijpyh/st4ky38yDFarlCtkE9sW3wCZ3hTM+clsu7NY9QytHexnPQbBM5e5vMsed48V9vNrkquF59//vw/V4fDKA=="; \ No newline at end of file +window.searchData = "eJy1nd1v2zgSwP+Vg/rqzWpI6itvQS89FMi1QNvdfTCKwusojnGOHUhKu0XR//1AirKH5NAa2e5TCkvzIfLH4WhGUn8kze5bm1zPfyT/W2/vk+tylmwXT3Vyndy9/8+X2z9v331KZslLs0muk3r78tT+vv/96rF72iSzZLlZtG3dJtdJ8nM26IF8r+j2w4f3H44qeVU3za5xVc2S50VTbzvHE1L/23dv3h9Xv94+7E7V/unDzevb4+q7ZrGsT9X/182Hd8fVf1s022naxWEWb/5utXvdzfNzvb2vm70pq+53/4Sjs5qB2Gte7rZt17wsux1T6StX4mCga+9/W7e/PTe7rl529T2+vsB/dJmpUHtv7uuHxcumu9utbr/W2+7NQlv5/uZly/TNym92q1rLP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3OJKyPaqj1WIxzO8bVkCSn+61s+AX2lcwh4WfW4uw7qWjQ0I2KNTtYY95N9d/GQBrRiOX7G2aerpfhk04oYOCRS3m4+d8IR86hRZjzAln43WGkDqFb8OiIfvgIXTK+AUt5K6J/GRjte+hWw87rkM8rhqOfZ8nz+rnerLd1cj3//PPn/wGiJHAs"; \ No newline at end of file diff --git a/docs/typedoc/classes/AbstractAppender.html b/docs/typedoc/classes/AbstractAppender.html index 7cb1614..2f68a09 100644 --- a/docs/typedoc/classes/AbstractAppender.html +++ b/docs/typedoc/classes/AbstractAppender.html @@ -1,18 +1,29 @@ AbstractAppender | officescripts-logging-framework
officescripts-logging-framework
    Preparing search index...

    Class AbstractAppenderAbstract

    Abstract base class for all log appenders. -This class defines shared utility methods to standardize log formatting, -label generation, and event validation across concrete appender implementations.

    -

    It relies on a LogEventFactory function to create log events, enabling flexible -and customizable event creation strategies. The LogEventFactory is validated on -construction to ensure it meets the expected signature. This design allows users -to supply custom event creation logic if needed.

    -

    Appenders such as ConsoleAppender and ExcelAppender should extend this class -to inherit consistent logging behavior and event creation via the LogEventFactory.

    -
      +Provides a common interface and shared functionality for concrete appender implementations.

      +

      Features:

      +
        +
      • Allows specifying the formatting of log events via a shared Layout (see Layout).
      • +
      • Uses a static LogEventFactory function type to create log events, enabling flexible and customizable event creation.
      • +
      • Implements the core logic for logging, delegating the actual delivery of log events to subclasses via the sendEvent method.
      • +
      +

      Usage:

      +
        +
      • Extend this class to implement specific appenders (e.g., ConsoleAppender, ExcelAppender).
      • +
      • Subclasses must implement the sendEvent(event, context) method to define how log events are delivered.
      • +
      +
      +
    • The static layout and log event factory are shared across all appenders.
    • +
    • Designed for extensibility and consistency across different output targets.
    • +
    +
      +
    • LOG_EVENT for the enumeration of log event types.
    • +
    • LogEvent for the structure of log events.
    • +
    • Layout for the layout used to format log events before sending them to appenders.
    • +
    • LayoutImpl for the default layout implementation.
    • Appender for the interface definition.
    • LogEventFactory for the factory function type used to create log events.
    • -
    • Layout for the layout used to format log events before sending them to appenders.
    -

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    • Constructs a new AbstractAppender instance. Nothing is initialized, because the class only has static properties that are lazy initialized or set by the user.

      -

      Returns AbstractAppender

    Properties

    defaultLogEventFactoryFun: LogEventFactory

    Methods

    • To ensure when invoking clearInstance in a sub-class it also clear (null) the last log event.

      -

      Returns void

      Mainly intended for testing purposes. The state of the singleton will be lost. -This method only exist in src folder, it won't be deployed in dist folder (production).

      -

    Properties

    defaultLogEventFactoryFun: LogEventFactory

    Default factory function to create LogEvent instances. Used in case it was not set before by the user.

    +

    Methods

    • To ensure when invoking clearInstance method in a sub-class it also clears (null) the last log event +sent to the appender.

      +

      Returns void

      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).

      +
    • 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.

      Parameters

      • arg1: string | LogEvent

        LogEvent or message string.

        -
      • Optionalarg2: LOG_EVENT

        LOG_EVENT, only required if arg1 is a string.

        +
      • Optionalarg2: LOG_EVENT

        LOG_EVENT type. Only required if arg1 is a string.

      • Optionalarg3: LogEventExtraFields

        extraFields, only used if arg1 is a string.

        -

      Returns void

      ScriptError if: -- arg1 is a string but arg2 is not provided or is not a valid LOG_EVENT. -- arg1 is not a valid LogEvent. -- The log event factory is not set or is not a valid function.

      -
        -
      • If arg1 is a string, it creates a new LogEvent using the provided message and event type.
      • +

    Returns void

    ScriptError if:

    +
      +
    • arg1 is a string but arg2 is not provided or is not a valid LOG_EVENT.
    • +
    • if the arg1 is not a string and arg1 is not a valid LogEvent.
    • +
    +
      +
    • If arg1 is a string, it creates a new LogEvent using the provided message and event type, and if presents extraFields.
    • If arg1 is already a LogEvent, it validates the event and sends it directly.
    • The method uses the static layout to format the log event before sending it to the appenders.
    • -
    • The arg3 parameter is optional and can be used to provide additional fields for the log event.
    • -
    • It relays on abstract method sendEvent to send the log event to the appropriate destination.
    • +
    • The arg3 parameter is optional and can be used to provide extra fields to create a log event, if arg1 is a string.
    • +
    • The Template pattern is used, i.e. it implements common logic for logging, but delegates the actual sending of the log event +to the 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
    -

    Returns void

    ScriptError if:

    +
      +
    • The event is not a valid LogEvent.
    • +
    +

    Subclasses must call setLastLogEvent(event) after successfully sending the event, otherwise getLastLogEvent() will not reflect the most recent log event.

    -

    Returns void

    ScriptError if the layout is not a valid Layout implementation.

    +
    +
    diff --git a/docs/typedoc/classes/ConsoleAppender.html b/docs/typedoc/classes/ConsoleAppender.html index 1e90806..00de864 100644 --- a/docs/typedoc/classes/ConsoleAppender.html +++ b/docs/typedoc/classes/ConsoleAppender.html @@ -1,22 +1,23 @@ -ConsoleAppender | officescripts-logging-framework
    officescripts-logging-framework
      Preparing search index...

      Class ConsoleAppender

      Singleton appender that logs messages to the console. It is used as default appender, +ConsoleAppender | officescripts-logging-framework

      officescripts-logging-framework
        Preparing search index...

        Class ConsoleAppender

        Singleton appender that logs messages to the console. It is used as default appender by this class and by LoggerImpl, if no other appender is defined. The content of the message event sent can be customized via any Layout implementation, but by default it uses the LayoutImpl. Usage:

        • Call ConsoleAppender.getInstance() to get the appender
        • Automatically used if no other appender is defined -Warning: The console appender is a singleton, so it should not be instantiated multiple times. -@example:
        • +Warning: The console appender is a singleton, so it should not be instantiated multiple times.
        -
        // Add console appender to the Logger
        Logger.addAppender(ConsoleAppender.getInstance()) +
        const appender = ConsoleAppender.getInstance() // Get the singleton instance
        appender.log("This is an info message", LOG_EVENT.INFO) // Log an info message
        // Better use:
        Logger.info("This is an info message") // uses the ConsoleAppender by default.
        -
          +
          +
        • LOG_EVENT for the log event types used to determine the color of the message.
        • +
        • LogEvent for the structure of log events.
        • Appender for the interface definition.
        • AbstractAppender for the base class documentation.
        • Layout for the layout used to format log events before sending them to the console.
        -

        Hierarchy (View Summary)

        Implements

        Index

        Hierarchy (View Summary)

        Implements

        Index

        Properties

        defaultLogEventFactoryFun: LogEventFactory

        Methods

        • To ensure when invoking clearInstance in a sub-class it also clear (null) the last log event.

          +

        Properties

        defaultLogEventFactoryFun: LogEventFactory

        Default factory function to create LogEvent instances. Used in case it was not set before by the user.

        +

        Methods

        • To ensure when invoking clearInstance method in a sub-class it also clears (null) the last log event +sent to the appender.

          Returns void

          Mainly intended for testing purposes. The state of the singleton will be lost. -This method only exist in src folder, it won't be deployed in dist folder (production).

          -

        Returns void

        ScriptError if:

        +
          +
        • arg1 is a string but arg2 is not provided or is not a valid LOG_EVENT.
        • +
        • if the arg1 is not a string and arg1 is not a valid LogEvent.
        • +
        -
        // 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 +
        // 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
        -

        Returns void

        ScriptError if

        +
          +
        • The event is not a valid LogEvent.
        • +
        • The instance is not available (not instantiated).
        • +
        +

        Returns void

        ScriptError if:

        +
          +
        • The event is not a valid LogEvent.
        • +

        Subclasses must call setLastLogEvent(event) after successfully sending the event, otherwise getLastLogEvent() will not reflect the most recent log event.

        -

        Returns void

        ScriptError if the layout is not a valid Layout implementation.

        +
        +
        diff --git a/docs/typedoc/classes/ExcelAppender.html b/docs/typedoc/classes/ExcelAppender.html index f0c68d5..5f27a9a 100644 --- a/docs/typedoc/classes/ExcelAppender.html +++ b/docs/typedoc/classes/ExcelAppender.html @@ -1,13 +1,16 @@ ExcelAppender | officescripts-logging-framework
        officescripts-logging-framework
          Preparing search index...

          Class ExcelAppender

          Singleton appender that logs messages to a specified Excel cell. Logs messages in color based on the LOG_EVENT enum:

            -
          • ERROR: red, WARN: orange, INFO: green, TRACE: gray (defaults can be customized) -Usage:
          • -
          • Must call ExcelAppender.getInstance(range) once with a valid single cell range
          • -
          • range is used to display log messages -Warning: The Excel appender is a singleton, so it should not be instantiated multiple times.
          • +
          • ERROR: red, WARN: orange, +INFO: green, TRACE: gray
          • +
          • Such colors can be customized by the user
          -
          const range = workbook.getWorksheet("Log").getRange("A1")
          Logger.addAppender(ExcelAppender.getInstance(range)) // Add appender to the Logger +

          Usage:

          +
            +
          • Must call ExcelAppender.getInstance(ExcelScript.Range) once with a valid single cell range.
          • +
          • The range is used to display log messages.
          • +
          +
          const range = workbook.getActiveWorksheet().getRange("A1")
          const appender = ExcelAppender.getInstance(range)
          appender.log("This is an info message", LOG_EVENT.INFO) // Log an info message
          // Better use:
          const logger = LoggerImpl.getInstance(LoggerImpl.LOG_LEVEL.INFO)
          logger.addAppender(appender) // Add the Excel appender to the logger
          logger.info("This is an info message")
            @@ -20,13 +23,14 @@
          • The appender validates the input range and colors when creating the instance.
            +
          • LOG_EVENT for the log event types used to determine the color of the message.
          • +
          • LogEvent for the structure of log events.
          • Appender for the interface definition.
          • AbstractAppender for the base class documentation.
          • -
          • LogEvent for the structure of log events.
          • Layout for the layout used to format log events before sending them to Excel.
          • -
          • ConsoleAppender for an example of a console appender that logs messages to the console.
          • +
          • ConsoleAppender Another implementation of the Appender interface that logs messages to the console.
          -

          Hierarchy (View Summary)

          Implements

          Index

          Hierarchy (View Summary)

          Implements

          Index

          Properties

          DEFAULT_EVENT_FONTS: Readonly<
              { "1": "9c0006"; "2": "ed7d31"; "3": "548235"; "4": "7f7f7f" },
          > = ...

          Default colors for log events, used if no custom colors are provided. -These colors are defined as hex strings (without the # prefix). The colors can be customized by passing a map of LOG_EVENT types to hex color strings -when calling getInstance(). Default colors are:

          +when calling getInstance(). Default colors are:

          • ERROR: 9c0006 red
          • WARN: ed7d31 orange
          • INFO: 548235 green
          • TRACE: 7f7f7f gray
          -
          defaultLogEventFactoryFun: LogEventFactory

          Methods

          • To ensure when invoking clearInstance in a sub-class it also clear (null) the last log event.

            +
          defaultLogEventFactoryFun: LogEventFactory

          Default factory function to create LogEvent instances. Used in case it was not set before by the user.

          +

          Methods

          • To ensure when invoking clearInstance method in a sub-class it also clears (null) the last log event +sent to the appender.

            Returns void

            Mainly intended for testing purposes. The state of the singleton will be lost. -This method only exist in src folder, it won't be deployed in dist folder (production).

            -
          • Returns the map of event types to font colors used by this appender.

            Returns Record<LOG_EVENT, string>

            A defensive copy of the event fonts map.

            The keys are LOG_EVENT enum values, and the values are hex color strings.

            -
          • Returns the Excel range where log messages are written.

            +
          • Returns the Excel range where log messages are written. +This range must be a single cell, and it is used to display log messages.

            Returns any

            The ExcelScript.Range object representing the message cell range.

            This is the cell where log messages will be displayed.

            -
          • 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.

            Parameters

            • arg1: string | LogEvent

              LogEvent or message string.

              -
            • Optionalarg2: LOG_EVENT

              LOG_EVENT, only required if arg1 is a string.

              +
            • Optionalarg2: LOG_EVENT

              LOG_EVENT type. Only required if arg1 is a string.

            • Optionalarg3: LogEventExtraFields

              extraFields, only used if arg1 is a string.

              -

            Returns void

            ScriptError if: -- arg1 is a string but arg2 is not provided or is not a valid LOG_EVENT. -- arg1 is not a valid LogEvent. -- The log event factory is not set or is not a valid function.

            +

          Returns void

          ScriptError if:

          +
            +
          • arg1 is a string but arg2 is not provided or is not a valid LOG_EVENT.
          • +
          • if the arg1 is not a string and arg1 is not a valid LogEvent.
          • +
            -
          • If arg1 is a string, it creates a new LogEvent using the provided message and event type.
          • +
          • If arg1 is a string, it creates a new LogEvent using the provided message and event type, and if presents extraFields.
          • If arg1 is already a LogEvent, it validates the event and sends it directly.
          • The method uses the static layout to format the log event before sending it to the appenders.
          • -
          • The arg3 parameter is optional and can be used to provide additional fields for the log event.
          • -
          • It relays on abstract method sendEvent to send the log event to the appropriate destination.
          • +
          • The arg3 parameter is optional and can be used to provide extra fields to create a log event, if arg1 is a string.
          • +
          • The Template pattern is used, i.e. it implements common logic for logging, but delegates the actual sending of the log event +to the 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
          -
          • Sets the value of the cell, with the event message, using the font defined for the event type, if not font was defined it doesn't change the font of the cell.

            Parameters

            • event: LogEvent

              a value from enum LOG_EVENT.

              -
            • Optionalcontext: string

            Returns void

            ScriptError in case event is not a valid LOG_EVENT enum value.

            -
          • Send the log event to the appropriate destination.

            +
          • Optionalcontext: string

            (Optional) A string to provide additional context in case of an error. +If not provided, it uses the class name and method name as context.

            +

          Returns void

          ScriptError In case event is not a valid LogEvent.

          +
          • Set the last log event sent to the appender.

            Parameters

            • event: LogEvent

              The log event to be sent.

              -

            Returns void

            ScriptError if -- The event is not a valid LogEvent.

            +

          Returns void

          ScriptError if:

          +
            +
          • The event is not a valid LogEvent.
          • +

          Subclasses must call setLastLogEvent(event) after successfully sending the event, otherwise getLastLogEvent() will not reflect the most recent log event.

          -
          • Shows instance configuration plus the message cell range address, the event fonts used, plus the parent information provided by toString method.

            +

            Returns string

            A string representation of the appender.

            +

            ScriptError, if the singleton was not instantiated.

            +
          • Sets to null the singleton instance, useful for running different scenarios. It also sets to null the parent property lastLogEvent, so the last log event is cleared.

            -

            Returns void

            const activeSheet = workbook.getActiveWorksheet() // workbook is input argument of main
            const msgCellRng = activeSheet.getRange("C2")
            appender = ExcelAppender.getInstance(msgCellRng) // with default log event colors
            appender.info("info event") // Output: In Excel in cell C2 with green color shows: "info event"
            // Now we want to test how getInstance() can throw a ScriptError,
            // but we can't because the instance was already created and it is a singleton we need clearInstance
            appender.clearInstance()
            appender = ExcelAppender.getInstance(null) // throws a ScriptError +

            Returns void

            const activeSheet = workbook.getActiveWorksheet() // workbook is input argument of main
            const msgCellRng = activeSheet.getRange("C2")
            appender = ExcelAppender.getInstance(msgCellRng) // with default log event colors
            appender.log("info event", LOG_EVENT.INFO) // Output: In cell C2 with green color: "info event"
            // Now we want to test how getInstance() can throw a ScriptError,
            // but we can't because the instance was already created and it is a singleton we need clearInstance
            appender.clearInstance()
            appender = ExcelAppender.getInstance(null) // throws a ScriptError

            Mainly intended for testing purposes. The state of the singleton will be lost. -This method only exist in src folder, it wont be deployed in dist folder (production).

            -
          • Sets to null the static layout, useful for running different scenarios.

            +This method is available only in src folder, it is not deployed in dist folder (production).

            +
          • Sets to null the static layout, useful for running different scenarios.

            Returns void

            Mainly intended for testing purposes. The state of the singleton will be lost. -This method only exist in src folder, it won't be deployed in dist folder (production).

            -
          • Sets to null the log event factory, useful for running different scenarios.

            +This method is available only in src folder, it is not deployed in dist folder (production).

            +
          • Sets to null the log event factory, useful for running different scenarios.

            Returns void

            Mainly intended for testing purposes. The state of the singleton will be lost. -This method only exist in src folder, it won't be deployed in dist folder (production).

            -
          • Returns the singleton ExcelAppender instance, creating it if it doesn't exist. On first call, requires a valid single cell Excel range to display log messages and optional color customizations for different log events (LOG_EVENT). Subsequent calls ignore parameters and return the existing instance.

            -

            Parameters

            • msgCellRng: any

              Excel range where log messages will be written. Must be a single cell and +

              Parameters

              • msgCellRng: any

                ExcelScript.Range where log messages will be written. Must be a single cell range and not null or undefined.

              • eventFonts: Record<LOG_EVENT, string> = ExcelAppender.DEFAULT_EVENT_FONTS

                Optional. A map of LOG_EVENT types to hex color codes for the font colors. If not provided, defaults to the predefined colors in DEFAULT_EVENT_FONTS. The user can provide just the colors they want to customize, -the rest will use the default colors.

                +the rest will use the default colors. These colors can be defined with or without # prefix.

              Returns ExcelAppender

              The singleton ExcelAppender instance.

              -

              ScriptError if msgCellRng was not defined or if the range covers multiple cells -or if it is not a valid Excel range. -if the font colors are not valid hexadecimal values for colors

              -
              const range = workbook.getWorksheet("Log").getRange("A1")
              const excelAppender = ExcelAppender.getInstance(range)
              ExcelAppender.getInstance(range, "ff0000") // ignored if called again +

              ScriptError if:

              +
                +
              • msgCellRng was not defined or if the range covers multiple cells
              • +
              • It is not a valid Excel range or the range doesn't represent a single cell.
              • +
              • The font colors are not valid hexadecimal values for colors
              • +
              +
              const range = workbook.getWorksheet("Log").getRange("A1")
              let excelAppender = ExcelAppender.getInstance(range)
              excelAppender.log("info event", LOG_EVENT.INFO)
              // Example using custom colors for errors events for the rest it uses the default colors:
              const customFonts: Record<LOG_EVENT, string> = {
              [LOG_EVENT.ERROR]: "0000FF", // blue
              }
              excelAppender.clearInstance() // Clear the singleton instance
              excelAppender = ExcelAppender.getInstance(range, customFonts)
              excelAppender.log("custom colored error event", LOG_EVENT.ERROR) // Output: In cell A1 with blue color: "custom colored error event"
          • Returns Layout

            The layout associated to all events. Used to format the log event before sending it to the appenders. +

          • Returns Layout

            The 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.

            Static, shared by all log events. Singleton.

            -
          • Sets the layout associated to all events, the layout is assigned only if it was not set before.

            Parameters

            • layout: Layout

              The layout to set.

              -

            Returns void

            ScriptError if the layout is not a valid Layout implementation.

            -
          • Sets the log event factory function used to create LogEvent instances if it was not set before.

            +

          Returns void

          ScriptError if the layout is not a valid Layout implementation.

          +
          • Sets the log event factory function used to create LogEvent instances if it was not set before.

            Parameters

            • logEventFactory: LogEventFactory

              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.

              @@ -143,4 +161,4 @@
              // 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
              -
          +
          diff --git a/docs/typedoc/classes/LayoutImpl.html b/docs/typedoc/classes/LayoutImpl.html index f9cfd56..ea08a9c 100644 --- a/docs/typedoc/classes/LayoutImpl.html +++ b/docs/typedoc/classes/LayoutImpl.html @@ -1,7 +1,7 @@ LayoutImpl | officescripts-logging-framework
          officescripts-logging-framework
            Preparing search index...

            Class LayoutImpl

            Default implementation of the Layout interface. Formats log events into a string using a provided or default formatting function.

              -
            • Uses the Strategy Pattern for extensibility: you can pass a custom formatting function (strategy) to the constructor.
            • +
            • Uses the Strategy Pattern for extensibility: you can pass a custom formatting function (strategy) to the constructor.
            • All events are validated to conform to the LogEvent interface before formatting.
            • Throws ScriptError if the event does not conform to the expected LogEvent interface.
            @@ -9,56 +9,50 @@
          • Layout for the interface definition.
          • LogEvent for the structure of log events.
          • -

            Implements

            Index

            Constructors

            Implements

            Index

            Constructors

            • Constructs a new LayoutImpl.

              -

              Parameters

              • Optionalformatter: LayoutFormatter

                Optional. A function that formats a LogEvent as a string. -If not provided, a default formatter is used: [timestamp] [type] message. -The formatter function synchronous and must accept a single LogEvent -parameter and return a string.

                -

              Returns LayoutImpl

              Strategy Pattern to allow flexible formatting via formatter function. -Pass a custom function to change the formatting logic at runtime.

              -

              ScriptError if: -- The formatter is not a function or does not have the expected arity (1 parameter). -- The formatter is null or undefined. -- The instance object is undefined or null (if subclassed or mutated in ways that break the interface).

              -
              // Using the default formatter:
              const layout = new LayoutImpl()
              // Using a custom formatter for JSON output:
              const jsonLayout = new LayoutImpl(event => JSON.stringify(event))
              // Using a formatter for XML output:
              const xmlLayout = new LayoutImpl(event =>
              `<log><type>${event.type}</type><message>${event.message}</message></log>`
              )
              // Using a shorter format [type] [message]:
              const shortLayout = new LayoutImpl(e => `[${LOG_EVENT[e.type]}] ${e.message}`)
              // Using a custom formatter with a named function, so in toString() shows the name of the formatter.
              let shortLayoutFun: Layout = new LayoutImpl(
              function shortLayoutFun(e:LogEvent):string{return `[${LOG_EVENT[e.type]}] ${e.message}`}) +

            Constructors

            • Constructs a new LayoutImpl with an optional custom formatter.

              +

              Parameters

              • Optionalformatter: LayoutFormatter

                (Optional) A function that formats a LogEvent as a string. +If omitted, uses the default formatter: [timestamp] [type] message. +The formatter must accept a single LogEvent parameter, and return a string.

                +

              Returns LayoutImpl

                +
              • Implements the Strategy Pattern: pass a custom formatter to change output format at runtime.
              • +
              • Formatter must be a function of arity 1; see LayoutFormatter.
              • +
              • Throws ScriptError if the formatter is invalid or the instance is misconfigured.
              • +
              +

              ScriptError if:

              +
                +
              • The formatter is not a function or does not accept exactly one argument.
              • +
              • The formatter is null or undefined.
              • +
              • The instance is null or undefined (e.g., due to subclassing or mutation).
              • +
              +
              // Default formatter:
              const layout = new LayoutImpl()

              // Custom JSON formatter:
              const jsonLayout = new LayoutImpl(event => JSON.stringify(event))

              // XML formatter:
              const xmlLayout = new LayoutImpl(event =>
              `<log><type>${event.type}</type><message>${event.message}</message></log>`
              )

              // Short format: [type] message
              const shortLayout = new LayoutImpl(e => `[${LOG_EVENT[e.type]}] ${e.message}`)

              // Named function for better diagnostics in toString():
              const namedShortLayout = new LayoutImpl(
              function shortLayoutFun(e: LogEvent): string { return `[${LOG_EVENT[e.type]}] ${e.message}` }
              )
              -

            Properties

            defaultFormatterFun: LayoutFormatter

            Convenience static property to define a long formatter used as default, e.g. [timestamp] [type] message. +

            Properties

            defaultFormatterFun: LayoutFormatter

            Convenience static property to define a long formatter used as default, e.g. [timestamp] [type] message. This is the default formatter used if no custom formatter is provided.

            -
            shortFormatterFun: LayoutFormatter

            Convenience static property to define a short formatter, e.g. [type] message.

            -

            Methods

            shortFormatterFun: LayoutFormatter

            Convenience static property to define a short formatter, e.g. [type] message.

            +

            Methods

            • Formats the given log event as a string.

              Parameters

              • event: LogEvent

                The log event to format.

              Returns string

              A string representation of the log event.

              ScriptError if the event does not conform to the LogEvent interface.

              -
            • Returns string

              A string representation of the layout. +

            • Returns string

              A string representation of the layout. If the formatter is a function, it returns the name of the function.

              -
            • Validates that the provided value is a valid formatter function -for use in LayoutImpl (_formatter property). The formatter must be -a function accepting a single LogEvent argument and must return a non-empty, non-null string.

              -

              Parameters

              • formatter: LayoutFormatter

                The candidate formatter function to validate.

                -
              • Optionalcontext: string

                (Optional) Additional context for error messages.

                -

              Returns void

              ScriptError if formatter is missing, not a function, doesn't have arity 1, -or returns null/empty string for a sample event.

              -
            • Asserts that the provided object implements the Layout interface. Checks for the public format method (should be a function taking one argument). -Also validates the internal _formatter property if present, by calling validateFormatter. -Used by appenders to validate layout objects at runtime.

              -

              Parameters

              • layout: Layout

                The object to validate as a Layout implementation.

                +It used by LayoutImpl and appenders to ensure that the layout is valid before using it.

                +

                Parameters

                • layout: Layout

                  The object to validate as a Layout implementation.

                • Optionalcontext: string

                  (Optional) Additional context for error messages.

                  -

                Returns void

                ScriptError if:

                +

              Returns void

              ScriptError if:

              • layout is null or undefined.
              • format is not a function or doesn't have arity 1.
              • -
              • _formatter is present and is missing, not a function, or doesn't have arity 1.
              -
            +
            diff --git a/docs/typedoc/classes/LogEventImpl.html b/docs/typedoc/classes/LogEventImpl.html index b7c0b75..94dd565 100644 --- a/docs/typedoc/classes/LogEventImpl.html +++ b/docs/typedoc/classes/LogEventImpl.html @@ -1,6 +1,5 @@ -LogEventImpl | officescripts-logging-framework
            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, and timestamp, along with methods to manage -the layout used for formatting log events before sending them to appenders.

              +LogEventImpl | officescripts-logging-framework
              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.
                • @@ -11,7 +10,7 @@
                • LogEvent for the interface definition.
                • LOG_EVENT for the enumeration of log event types.
                -

                Implements

                Index

                Constructors

                Implements

                Index

                Constructors

                Accessors

                extraFields message timestamp @@ -36,19 +35,18 @@
              • 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.
              • -

                Accessors

                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 string

                  A string representation of the log event in standard toString format

                  -

                Methods

                • Returns string

                  A string representation of the log event in standard toString format

                  +
                • 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).

                  +
                • 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.

                  -
                +
                diff --git a/docs/typedoc/classes/LoggerImpl.html b/docs/typedoc/classes/LoggerImpl.html index 7bdbdcf..b0188ce 100644 --- a/docs/typedoc/classes/LoggerImpl.html +++ b/docs/typedoc/classes/LoggerImpl.html @@ -1,20 +1,27 @@ -LoggerImpl | officescripts-logging-framework
                officescripts-logging-framework
                  Preparing search index...

                  Class LoggerImpl

                  Singleton class that manages application logging through appenders. -Supports the following log events: ERROR, WARN, INFO, TRACE (LOG_EVENT enum). -Supports the level of information (verbose) to show via Logger.LEVEL: OFF, ERROR, WARN, INFO, TRACE. -If the level of information (LEVEL) is OFF, no log events will be sent to the appenders. -Supports the action to take in case of ERROR, WARN log events: the script can -continue (Logger.ACTION.CONTINUE), or abort (Logger.ACTION.EXIT). Such actions only take effect -if the LEVEL is not Logger.LEVEL.OFF. -Allows defining appenders, controlling the channels the events are sent to. -Collects error/warning sent by the appenders via getCriticalEvents().

                  +LoggerImpl | officescripts-logging-framework
                  officescripts-logging-framework
                    Preparing search index...

                    Class LoggerImpl

                    Singleton class that manages application logging through appenders.

                    +
                      +
                    • Supports the following log events: ERROR, WARN, INFO, TRACE (LOG_EVENT enum).
                    • +
                    • Supports the level of information (verbose) to show via LoggerImpl.LEVEL: OFF, ERROR, WARN, INFO, TRACE, +where WARN is the default maximum level of verbosity.
                    • +
                    • If the level of information (LEVEL) is OFF, no log events will be sent to the appenders.
                    • +
                    • Supports the action to take in case of ERROR, WARN log events: the script can +continue (LoggerImpl.ACTION.CONTINUE), or abort (LoggerImpl.ACTION.EXIT default). Such actions only take effect +if the LEVEL is not LoggerImpl.LEVEL.OFF.
                    • +
                    • Allows defining appenders, controlling the channels the events are sent to.
                    • +
                    • Collects error/warning sent by the appenders via getCriticalEvents().
                    • +

                    Usage:

                      -
                    • Initialize with Logger.getInstance(level, action).
                    • -
                    • Add one or more appenders (e.g. ConsoleAppender, ExcelAppender)
                    • +
                    • Initialize with LoggerImpl.getInstance(level, action).
                    • +
                    • Add one or more appenders (e.g. ConsoleAppender, ExcelAppender), via addAppender() for example.
                    • Use logger.error(), logger.warn(), logger.info(), or logger.trace() to log.

                    Features:

                      +
                    • Supports multiple appenders, allowing logs to be sent to different destinations (e.g., console, Excel).
                    • +
                    • If when invoking any log method (e.g. logger.error()) if the singleton was not instantiated, +it does a lazy initialization of the logger with default configuration, +i.e. LoggerImpl.LEVEL=WARN and LoggerImpl.ACTION=EXIT.
                    • If no appender is added, ConsoleAppender is used by default.
                    • Logs are routed through all registered appenders.
                    • Collects a summary of error/warning messages and counts. @@ -22,7 +29,7 @@ This ensures that log messages are not silently dropped. You may replace or remove this appender at any time using setAppenders() or removeAppender().
                    -
                    // Minimal logger usage; ConsoleAppender is auto-added if none specified
                    LoggerImpl.getInstance().info("This message will appear in the console by default. +
                    // Minimal logger usage; ConsoleAppender is auto-added if none specified
                    LoggerImpl.getInstance().error("This message will appear in the console by default.")
                      @@ -31,7 +38,7 @@
                    • ConsoleAppender for the implementation details of the console appender.
                    • LogEvent for the structure of log events.
                    -

                    Implements

                    Index

                    Properties

                    Implements

                    Index

                    Properties

                    Methods

                    Properties

                    ACTION: Readonly<{ CONTINUE: 0; EXIT: 1 }> = ...

                    Static constant (enum pattern) for log event types.

                    -
                    LEVEL: Readonly<{ OFF: number } & typeof LOG_EVENT> = ...

                    Static 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

                    -

                    Methods

                    • Adds an appender to the list of appenders.

                      +

                    Properties

                    ACTION: Readonly<{ CONTINUE: 0; EXIT: 1 }> = ...

                    Static 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.
                    • +
                    +
                    LEVEL: Readonly<{ OFF: number } & typeof LOG_EVENT> = ...

                    Static 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.

                    +

                    Methods

                    • Adds an appender to the list of appenders.

                      Parameters

                      • appender: Appender

                        The appender to add.

                        -

                      Returns void

                      ScriptError If the singleton was not instantiated, -if the input argument is null or undefined, -or if it breaks the class uniqueness of the appenders. -All appenders must be from a different implementation of the Appender class.

                      -
                    • 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 Logger.LEVEL.ERROR to send this event to the appenders. +

                    Returns void

                    ScriptError If:

                    +
                      +
                    • The singleton was not instantiated,
                    • +
                    • The input argument is null or undefined,
                    • +
                    • It breaks the class uniqueness of the appenders. All appenders must be from a different implementation of the Appender class.
                    • +
                    +
                    • 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.

                      Parameters

                      • msg: string

                        The error message to log.

                      • OptionalextraFields: LogEventExtraFields

                        Optional structured data to attach to the log event (e.g., context info, tags).

                      Returns void

                      If no singleton was defined, it does lazy initialization with default configuration. If no appender was defined, it does lazy initialization to ConsoleAppender.

                      -

                      ScriptError If level is greater than Logger.LEVEL.OFF and the action is Logger.ACTION.EXIT. -If any internal error occurs while sending the event to the appenders.

                      -
                    • Serializes the current state of the logger to a plain object, useful for +

                      ScriptError If:

                      +
                        +
                      • Level is greater than LoggerImpl.LEVEL.OFF and the action is LoggerImpl.ACTION.EXIT.
                      • +
                      • If any internal error occurs while sending the event to the appenders.
                      • +
                      +
                    • 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.

                      Returns {
                          action: string;
                          criticalEvents: LogEvent[];
                          errorCount: number;
                          level: string;
                          warningCount: number;
                      }

                      A structure with key information about the logger, such as: level, action, errorCount, warningCount, and criticalEvents.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns 0 | 1

                      The action to take in case of errors or warning log events.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns number

                      Total number of error message events sent to the appenders.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns the level of verbosity allowed in the Logger. The levels are incremental, i.e. -it includes all previous levels. For example: Logger.WARN includes warnings and errors since -Logger.ERROR is lower.

                      +
                    • 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.

                      Returns number

                      The current log level.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns number

                      Total number of warning events sent to the appenders.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns boolean

                      true if some error or warning event has been sent by the appenders, otherwise false.

                      +
                    • Returns boolean

                      true if some error or warning event has been sent by the appenders, otherwise false.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns boolean

                      true if an error log event was sent to the appenders, otherwise false.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns boolean

                      true if a warning log event was sent to the appenders, otherwise false.

                      +
                    • Returns boolean

                      true if a warning log event was sent to the appenders, otherwise false.

                      ScriptError If the singleton was not instantiated.

                      -
                    • 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 Logger.LEVEL.INFO to send this event to the appenders.

                      +
                    • 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.

                      Parameters

                      • msg: string

                        The informational message to log.

                      • OptionalextraFields: LogEventExtraFields

                        Optional structured data to attach to the log event (e.g., context info, tags).

                      Returns void

                      ScriptError If any internal error occurs while sending the event to the appenders.

                      -

                      If no singleton was defined, it does lazy initialization with default configuration. -If no appender was defined, it does lazy initialization to ConsoleAppender.

                      -
                    • If the list of appenders is not empty, removes the appender from the list.

                      +
                        +
                      • If no singleton was defined, it does lazy initialization with default configuration.
                      • +
                      • If no appender was defined, it does lazy initialization to ConsoleAppender.
                      • +
                      +
                    • If the list of appenders is not empty, removes the appender from the list.

                      Parameters

                      • appender: Appender

                        The appender to remove.

                      Returns void

                      ScriptError If the singleton was not instantiated.

                      -
                    • Resets the Logger history, i.e., state (errors, warnings, including the list of critical events). It doesn't reset the appenders.

                      +
                    • Resets the Logger history, i.e., state (errors, warnings, including the list of critical events). It doesn't reset the appenders.

                      Returns void

                      ScriptError If the singleton was not instantiated.

                      -
                    • Sets the array of appenders with the input argument appenders.

                      Parameters

                      • appenders: Appender[]

                        Array with all appenders to set.

                        -

                      Returns void

                      ScriptError If the singleton was not instantiated, -if appenders is null or undefined, or contains -null or undefined entries, -or if the appenders to add are not unique -by appender class. See JSDoc from LoggerImpl.addAppender for more details.

                      -
                    • Short version fo the toString() which exludes the appenders details.

                      +

                    Returns void

                    ScriptError If:

                    +
                      +
                    • The singleton was not instantiated.
                    • +
                    • appenders is null or undefined, or contains null or undefined entries.
                    • +
                    • The appenders to add are not unique +by appender class. See JSDoc from LoggerImpl.addAppender for more details.
                    • +
                    +
                    • Short version of the toString() which excludes the appenders details.

                      Returns string

                      Similar to toString, but showing the list of appenders name only.

                      ScriptError If the singleton was not instantiated.

                      -
                    • Returns string

                      A string representation of the logger instance. +toString() includes the logger's level, action, error count, warning count, +and a list of appenders with their string representations.

                      ScriptError If the singleton was not instantiated.

                      -
                    • 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 Logger.LEVEL.TRACE to send this event to the appenders.

                      +
                    • 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.

                      Parameters

                      • msg: string

                        The trace message to log.

                      • OptionalextraFields: LogEventExtraFields

                        Optional structured data to attach to the log event (e.g., context info, tags).

                      Returns void

                      ScriptError If any internal error occurs while sending the event to the appenders.

                      -

                      If no singleton was defined, it does lazy initialization with default configuration. -If no appender was defined, it does lazy initialization to ConsoleAppender.

                      -
                    • 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 Logger.LEVEL.WARN to send this event to the appenders. +

                        +
                      • If no singleton was defined, it does lazy initialization with default configuration.
                      • +
                      • If no appender was defined, it does lazy initialization to ConsoleAppender.
                      • +
                      +
                    • 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.

                      Parameters

                      • msg: string

                        The warning message to log.

                      • OptionalextraFields: LogEventExtraFields

                        Optional structured data to attach to the log event (e.g., context info, tags).

                        -

                      Returns void

                      ScriptError If level is greater than Logger.LEVEL.ERROR and the action is Logger.ACTION.EXIT. -If any internal error occurs while sending the event to the appenders.

                      -

                      If no singleton was defined, it does lazy initialization with default configuration. -If no appender was defined, it does lazy initialization to ConsoleAppender.

                      -
                    • Sets the singleton instance to null, useful for running different scenarios.

                      +

                    Returns void

                    ScriptError If:

                    +
                      +
                    • Level is greater than LoggerImpl.LEVEL.ERROR and the action is LoggerImpl.ACTION.EXIT.
                    • +
                    • Any internal error occurs while sending the event to the appenders.
                    • +
                    +
                      +
                    • If no singleton was defined, it does lazy initialization with default configuration.
                    • +
                    • If no appender was defined, it does lazy initialization to ConsoleAppender.
                    • +
                    +
                    • Sets the singleton instance to null, useful for running different scenarios and testing purposes.

                      Returns void

                      Mainly intended for testing purposes. The state of the singleton will be lost. -This method only exist in src folder, it won't be deployed in dist folder (production). +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.

                      ScriptError If the singleton was not instantiated.

                      -
                      // 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 = Logger.getInstance() // LEVEL: WARN, ACTION: EXIT
                      logger.error("error event") // Output: "error event" and ScriptError
                      // Now we want to test with the following configuration: Logger.LEVEL:WARN, Logger.ACTION:CONTINUE
                      Logger.clearInstance() // Clear the singleton
                      logger = Logger.getInstance(LEVEL.WARN, ACTION.CONTINUE)
                      logger.error("error event") // Output: "error event" (no ScriptError was thrown) +
                      // 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)
                      -
                    • Returns the label for a log action value.

                      +
                    • Returns the label for a log action value.

                      Parameters

                      • Optionalaction: 0 | 1

                        The log action to get the label for.

                        -

                      Returns string

                      The label for the action. -If action is undefined, returns the label for the current logger instance's action. -If neither is set, returns UNKNOWN.

                      +

                    Returns string

                    The label for the action.

                    +
                      +
                    • If action is undefined, returns the label for the current logger instance's action.
                    • +
                    • If neither is set, returns UNKNOWN.
                    • +
                    LoggerImpl.getActionLabel(LoggerImpl.ACTION.CONTINUE) // Returns "CONTINUE"
                    LoggerImpl.getActionLabel() // Returns the current logger instance's action label
                    -
                    • Returns the singleton Logger instance, creating it if it doesn't exist. +

                    • Returns 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.

                      -

                      Parameters

                      • level: number = LoggerImpl.DEFAULT_LEVEL

                        The verbosity level (default: Logger.LEVEL.WARN). Controls verbosity. +

                        Parameters

                        • level: number = LoggerImpl.DEFAULT_LEVEL

                          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 -Logger.LEVEL.OFF, which suppresses all messages sent to the appenders. -For example: Logger.LEVEL.INFO allows sending errors, warnings, and information events, +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.

                          -
                        • action: 0 | 1 = LoggerImpl.DEFAULT_ACTION

                          The action on error/warning (default: Logger.ACTION.EXIT). +

                        • action: 0 | 1 = LoggerImpl.DEFAULT_ACTION

                          The action on error/warning (default: LoggerImpl.ACTION.EXIT). Determines if the script should continue or abort. -If the value is Logger.ACTION.EXIT, throws a ScriptError exception, -i.e. aborts the Script. If the action is Logger.ACTION.CONTINUE, the -script continues. It only takes effect if the level is not Logger.LEVEL.OFF.

                          +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.

                        Returns LoggerImpl

                        The singleton Logger instance.

                        Subsequent calls ignore these parameters and return the existing instance.

                        -

                        ScriptError If the level input value was not defined in Logger.LEVEL or it doesn't -match the LOG_EVENT enum values in the specified order. -If the action input value was not defined in Logger.ACTION.

                        -
                        // Initialize logger at INFO level, continue on errors/warnings
                        const logger = Logger.getInstance(Logger.LEVEL.INFO, Logger.ACTION.CONTINUE)
                        // Subsequent calls ignore parameters, return the same instance
                        const sameLogger = Logger.getInstance(Logger.LEVEL.ERROR, Logger.ACTION.EXIT)
                        logger.info("Starting the Script") // Send this message to all appenders
                        logger.trace("Step one") // Doesn't send because of Logger.LEVEL value: INFO +

                        ScriptError If:

                        +
                          +
                        • The level input value was not defined in LoggerImpl.LEVEL or it doesn't +match the LOG_EVENT enum values in the specified order.
                        • +
                        • The action input value was not defined in 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
                        -
                    • Returns the label for the given log level.

                      -

                      Parameters

                      • Optionallevel: number

                      Returns string

                      The label for the log level. -If level is undefined, returns the label for the current logger instance's level. -If neither is set, returns UNKNOWN.

                      +
                    • Returns the label for the given log level.

                      +

                      Parameters

                      • Optionallevel: number

                      Returns string

                      The label for the log level.

                      +
                        +
                      • If level is undefined, returns the label for the current logger instance's level.
                      • +
                      • If neither is set, returns UNKNOWN.
                      • +
                      LoggerImpl.getLevelLabel(LoggerImpl.LEVEL.INFO) // Returns "INFO"
                      LoggerImpl.getLevelLabel() // Returns the current logger instance's level label
                      -
                    +
                    diff --git a/docs/typedoc/classes/ScriptError.html b/docs/typedoc/classes/ScriptError.html index 44fd45b..eae11f5 100644 --- a/docs/typedoc/classes/ScriptError.html +++ b/docs/typedoc/classes/ScriptError.html @@ -7,7 +7,7 @@
                    const original = new Error("Missing field")
                    throw new ScriptError("Validation failed", original)
                    -

                    Hierarchy

                    • Error
                      • ScriptError
                    Index

                    Constructors

                    Hierarchy

                    • Error
                      • ScriptError
                    Index

                    Constructors

                    Properties

                    cause? message name @@ -21,9 +21,9 @@

                    Parameters

                    • message: string

                      A description of the error.

                    • Optionalcause: Error

                      (Optional) The original error that caused this one. If provided the exception message will have a reference to the cause.

                      -

                    Returns ScriptError

                    Properties

                    cause?: Error

                    (Optional) The original error that caused this one. +

                    Returns ScriptError

                    Properties

                    cause?: Error

                    (Optional) The original error that caused this one. If provided the exception message will have a reference to the cause.

                    -
                    message: string
                    name: string
                    stack?: string
                    stackTraceLimit: number

                    The Error.stackTraceLimit property specifies the number of stack frames +

                    message: string
                    name: string
                    stack?: string
                    stackTraceLimit: number

                    The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

                    The default value is 10 but may be set to any valid JavaScript number. Changes @@ -34,13 +34,13 @@ otherwise rethrows this ScriptError itself. Useful for deferring a controlled exception and then surfacing the root cause explicitly.

                    -

                    Returns never

                    • Override toString() method.

                      +

                      Returns never

                    • Override toString() method.

                      Returns string

                      The name and the message on the first line, then on the second line the Stack trace section name, i.e. 'Stack trace:'. Starting on the third line the stack trace information. If a cause was provided the stack trace will refer to the cause otherwise to the original exception.

                      -
                    • Creates a .stack property on targetObject, which when accessed returns +

                    • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

                      const myObject = {};
                      Error.captureStackTrace(myObject);
                      myObject.stack; // Similar to `new Error().stack` diff --git a/docs/typedoc/classes/Utility.html b/docs/typedoc/classes/Utility.html index eb7c322..61d16da 100644 --- a/docs/typedoc/classes/Utility.html +++ b/docs/typedoc/classes/Utility.html @@ -1,5 +1,5 @@ Utility | officescripts-logging-framework
                      officescripts-logging-framework
                        Preparing search index...

                        Class Utility

                        Utility class providing static helper methods for logging operations.

                        -
                        Index

                        Constructors

                        Index

                        Constructors

                        Methods

                        date2Str isEmptyArray validateLogEventFactory @@ -7,9 +7,12 @@ where SSS is the milliseconds part padded to 3 digits.

                        Parameters

                        • date: Date

                          The date to format.

                        Returns string

                        A string representation of the date in the format YYYY-MM-DD HH:mm:ss,SSS.

                        -
                      • Helper method to check for an empty array.

                        -

                        Type Parameters

                        • T

                        Parameters

                        • arr: T[]

                        Returns boolean

                      • Validates a log event factory is a function.

                        +
                      • Helper method to check for an empty array.

                        +

                        Type Parameters

                        • T

                        Parameters

                        • arr: T[]

                        Returns boolean

                      • Validates a log event factory is a function.

                        Parameters

                        • factory: unknown

                          The factory function to validate.

                        • OptionalfunName: string

                          Used to identify the function name in the error message.

                        • Optionalcontext: string

                        Returns void

                        ScriptError if the log event factory is not a function.

                        -
                      +

                      Identical method already defined in AbstractAppender just keep it here in case in the future it can be used +by other classes that need to validate a log event factory. At this time is not used but the test cases where +defined for this class in test/main.ts so we keep it for potential future use.

                      +
                      diff --git a/docs/typedoc/enums/LOG_EVENT.html b/docs/typedoc/enums/LOG_EVENT.html index 6c6d902..4adc57a 100644 --- a/docs/typedoc/enums/LOG_EVENT.html +++ b/docs/typedoc/enums/LOG_EVENT.html @@ -1,19 +1,19 @@ LOG_EVENT | officescripts-logging-framework
                      officescripts-logging-framework
                        Preparing search index...

                        Enumeration LOG_EVENT

                        Enum representing log event types. Each value corresponds to a the level of verbosity and is used internally to filter messages. -Logger.LEVEL static constants was implemented in a way to align with the order of the enum +LoggerImpl.LEVEL static constants was implemented in a way to align with the order of the enum LOG_EVENT, so the order on how the LOG_EVENT values are defined matters.

                        Important:

                          -
                        • If new values are added, update the logic in related classes (e.g. ExcelAppender, Logger, etc.).
                        • -
                        • Don't start the LOG_EVENT enum with 0, this value is reserved for Logger.LEVEL -for not sending log events (Logger.LEVEL.OFF). +
                        • If new values are added, update the logic in related classes (e.g. ConsoleAppender, ExcelAppender, LoggerImpl, etc.).
                        • +
                        • Don't start the LOG_EVENT enum with 0, this value is reserved for LoggerImpl.LEVEL +for not sending log events (LoggerImpl.LEVEL.OFF). It ensures the verbose level values are aligned with the LOG_EVENT enum. -Logger.LEVEL is built based on LOG_EVENT, just adding as first value 0, i.e. -Logger.OFF, therefore the verbosity respects the same order of the LOG_EVENT.
                        • +LoggerImpl.LEVEL is built based on LOG_EVENT, just adding as first value 0, i.e. +LoggerImpl.OFF, therefore the verbosity respects the same order of the LOG_EVENT.

                        It was defined as an independent entity since it is used by appenders and by the Logger.

                        -
                        Index

                        Enumeration Members

                        Index

                        Enumeration Members

                        Enumeration Members

                        ERROR: 1
                        INFO: 3
                        TRACE: 4
                        WARN: 2
                        +

                        Enumeration Members

                        ERROR: 1
                        INFO: 3
                        TRACE: 4
                        WARN: 2
                        diff --git a/docs/typedoc/interfaces/Appender.html b/docs/typedoc/interfaces/Appender.html index 91d7dc5..ab7d75a 100644 --- a/docs/typedoc/interfaces/Appender.html +++ b/docs/typedoc/interfaces/Appender.html @@ -9,11 +9,11 @@
                      • Appenders are responsible for sending log events, not formatting (core formatting is handled by the Layout interface).
                      • Implementations should be stateless or minimize instance state except for tracking the last sent event.
                      • -
                      • Common formatting and event creation concerns (such as layout or logEventFactory) are handled by the AbstractAppender base class +
                      • Common formatting and event creation concerns (such as layout or log event factory) are handled by the AbstractAppender base class and are not part of the interface contract.
                      • getLastLogEvent() is primarily for diagnostics, testing, or error reporting.
                      • toString() must return diagnostic information about the appender and its last log event.
                      • -
                      • Provides to log methods sending a LogEvent object or a message with an event type and optional extra fields. +
                      • Provides to log methods sending a LogEvent object or a message with an event type and optional extra fields. This allows flexibility in how log events are created and sent.
                        • @@ -22,20 +22,21 @@
                        • Layout for the layout used to format log events before sending them to appenders.
                        • LOG_EVENT for the enumeration of log event types.
                        -
                        interface Appender {
                            getLastLogEvent(): LogEvent;
                            log(event: LogEvent): void;
                            log(msg: string, type: LOG_EVENT, extraFields?: object): void;
                            toString(): string;
                        }

                        Implemented by

                        Index
                        interface Appender {
                            getLastLogEvent(): LogEvent;
                            log(event: LogEvent): void;
                            log(msg: string, type: LOG_EVENT, extraFields?: object): void;
                            toString(): string;
                        }

                        Implemented by

                        Index

                        Methods

                        • Returns the last LogEvent delivered to the appender, or null if none sent yet.

                          Returns LogEvent

                          The last LogEvent object delivered, or null.

                          ScriptError if the appender instance is unavailable.

                          -
                        • Sends a structured log event to the appender.

                          Parameters

                          • event: LogEvent

                            The log event object to deliver.

                          Returns void

                          ScriptError if the event is invalid or cannot be delivered.

                          -
                        • Sends a log message to the appender, specifying the event type and optional structured extra fields.

                          +
                        • Sends a log message to the appender, specifying the event type and optional structured extra fields.

                          Parameters

                          • msg: string

                            The message to log.

                          • type: LOG_EVENT

                            The type of log event (from LOG_EVENT enum).

                          • OptionalextraFields: object

                            Optional structured data (object) to attach to the log event (e.g., context info, tags).

                            -

                          Returns void

                        • Returns a string summary of the appender's state, typically including its type and last event.

                          +

                        Returns void

                        ScriptError if the log message is invalid or cannot be delivered.

                        +
                        • Returns a string summary of the appender's state, typically including its type and last event.

                          Returns string

                          A string describing the appender and its most recent activity.

                          -

                          ScriptError if the appender instance is unavailable.

                          -
                        +

                        ScriptError if the appender instance is unavailable.

                        +
                        diff --git a/docs/typedoc/interfaces/Layout.html b/docs/typedoc/interfaces/Layout.html index b4c5ce2..2b6c532 100644 --- a/docs/typedoc/interfaces/Layout.html +++ b/docs/typedoc/interfaces/Layout.html @@ -9,11 +9,12 @@
                      • Layouts are intended for core message structure, not for display/presentation logic.
                      • LogEvent for the structure of log events.

                        -
                        interface Layout {
                            format(event: LogEvent): string;
                            toString(): string;
                        }

                        Implemented by

                        Index

                        Methods

                        interface Layout {
                            format(event: LogEvent): string;
                            toString(): string;
                        }

                        Implemented by

                        Index

                        Methods

                        • Formats the given log event into its core string representation.

                          Parameters

                          • event: LogEvent

                            The log event to format (must be a valid, immutable LogEvent).

                          Returns string

                          The formatted string representing the event's core content. The formatted event will be the output of the appender.

                          -
                        • Returns a string describing the layout, ideally including the formatter function name or configuration. +

                          ScriptError if the event is invalid or cannot be formatted.

                          +
                        • Returns a string describing the layout, ideally including the formatter function name or configuration. Used for diagnostics or debugging.

                          -

                          Returns string

                        +

                        Returns string

                        diff --git a/docs/typedoc/interfaces/LogEvent.html b/docs/typedoc/interfaces/LogEvent.html index e8578ab..b0f3b2e 100644 --- a/docs/typedoc/interfaces/LogEvent.html +++ b/docs/typedoc/interfaces/LogEvent.html @@ -17,7 +17,7 @@
                      • Layout for the layout used to format log events before sending them to appenders.
                      • Appender for the interface that handles sending log events to output channels.
                      • -
                        interface LogEvent {
                            extraFields: LogEventExtraFields;
                            message: string;
                            timestamp: Date;
                            type: LOG_EVENT;
                            toString(): string;
                        }

                        Implemented by

                        Index

                        Properties

                        interface LogEvent {
                            extraFields: LogEventExtraFields;
                            message: string;
                            timestamp: Date;
                            type: LOG_EVENT;
                            toString(): string;
                        }

                        Implemented by

                        Index

                        Properties

                        extraFields message timestamp type @@ -25,14 +25,14 @@

                        Properties

                        extraFields: LogEventExtraFields

                        Additional metadata for the log event, for extension and contextual purposes. This field is immutable and must be a plain object. Intended for extensibility—avoid storing sensitive or large data here.

                        -
                        message: string

                        The log message to be sent to the appenders. +

                        message: string

                        The log message to be sent to the appenders. This field is immutable. It must not be null, undefined, or an empty string.

                        -
                        timestamp: Date

                        The timestamp when the event was created. +

                        timestamp: Date

                        The timestamp when the event was created. This field is immutable and must be a valid Date instance.

                        -
                        type: LOG_EVENT

                        The event type from the LOG_EVENT enum. +

                        type: LOG_EVENT

                        The event type from the LOG_EVENT enum. This field is immutable and must be set at construction.

                        -

                        Methods

                        • Returns a string representation of the log event in a human-readable, single-line format, +

                        Methods

                        • Returns a string representation of the log event in a human-readable, single-line format, including all relevant fields. It is expected to be implemented in a standardized way across all implementations.

                          Returns string

                          A string representation of the log event.

                          -
                        +
                        diff --git a/docs/typedoc/interfaces/Logger.html b/docs/typedoc/interfaces/Logger.html index 6fbbca4..056dcf8 100644 --- a/docs/typedoc/interfaces/Logger.html +++ b/docs/typedoc/interfaces/Logger.html @@ -2,13 +2,16 @@ Provides methods for logging messages, querying log state, managing appenders, and exporting logger state. Implementations should ensure they should not maintain global mutable state outside the singleton and efficient log event handling.

                        -
                          +
                          +
                        • Usually the LoggerImpl implementation should be implemented via singleton pattern.
                        • +
                        +
                        • LogEvent for the structure of log events.
                        • Appender for the interface that handles sending log events to output channels.
                        • LOG_EVENT for the enumeration of log event types.
                        • Layout for the layout used to format log events before sending them to appenders.
                        -
                        interface Logger {
                            addAppender(appender: Appender): void;
                            error(msg: string, extraFields?: object): void;
                            exportState(): {
                                action: string;
                                criticalEvents: LogEvent[];
                                errorCount: number;
                                level: string;
                                warningCount: number;
                            };
                            getAction(): number;
                            getAppenders(): Appender[];
                            getCriticalEvents(): LogEvent[];
                            getErrCnt(): number;
                            getLevel(): number;
                            getWarnCnt(): number;
                            hasCriticalEvents(): boolean;
                            hasErrors(): boolean;
                            hasWarnings(): boolean;
                            info(msg: string, extraFields?: object): void;
                            removeAppender(appender: Appender): void;
                            reset(): void;
                            setAppenders(appenders: Appender[]): void;
                            toString(): string;
                            trace(msg: string, extraFields?: object): void;
                            warn(msg: string, extraFields?: object): void;
                        }

                        Implemented by

                        Index

                        Methods

                        interface Logger {
                            addAppender(appender: Appender): void;
                            error(msg: string, extraFields?: object): void;
                            exportState(): {
                                action: string;
                                criticalEvents: LogEvent[];
                                errorCount: number;
                                level: string;
                                warningCount: number;
                            };
                            getAction(): number;
                            getAppenders(): Appender[];
                            getCriticalEvents(): LogEvent[];
                            getErrCnt(): number;
                            getLevel(): number;
                            getWarnCnt(): number;
                            hasCriticalEvents(): boolean;
                            hasErrors(): boolean;
                            hasWarnings(): boolean;
                            info(msg: string, extraFields?: object): void;
                            removeAppender(appender: Appender): void;
                            reset(): void;
                            setAppenders(appenders: Appender[]): void;
                            toString(): string;
                            trace(msg: string, extraFields?: object): void;
                            warn(msg: string, extraFields?: object): void;
                        }

                        Implemented by

                        Index

                        Methods

                        Methods

                        • Adds a new appender to the logger.

                          Parameters

                          • appender: Appender

                            The Appender instance to add.

                            -

                          Returns void

                          ScriptError if -- The singleton instance is not available (not instantiated). -- The appender is null or undefined. -- The appender is already registered in the logger.

                          +

                        Returns void

                        ScriptError if:

                        +
                          +
                        • The singleton instance is not available (not instantiated).
                        • +
                        • The appender is null or undefined.
                        • +
                        • The appender is already registered in the logger.
                        • +

                        Logger.setAppenders for setting multiple appenders at once and for more details on the validation of the appenders.

                        -
                        • Sends an error log event with the provided message and optional extraFields to all appenders.

                          +
                        • Sends an error log event with the provided message and optional extraFields to all appenders.

                          Parameters

                          • msg: string

                            The error message to log.

                          • OptionalextraFields: object

                            Optional structured data (object) to attach to the log event. May include metadata, context, etc.

                            -

                          Returns void

                          ScriptError if -- The singleton instance is not available (not instantiated) -- The logger is configured to exit on critical events.

                          -
                        • Exports the current state of the logger, including level, action, error/warning counts, and critical events.

                          +

                        Returns void

                        ScriptError if:

                        +
                          +
                        • The singleton instance is not available (not instantiated)
                        • +
                        • The logger is configured to exit on critical events such as warnings and errors.
                        • +
                        +
                        • Exports the current state of the logger, including level, action, error/warning counts, and critical events (warnings and errors).

                          Returns {
                              action: string;
                              criticalEvents: LogEvent[];
                              errorCount: number;
                              level: string;
                              warningCount: number;
                          }

                          An object containing the logger's state.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Gets the current action setting for error/warning events.

                          +
                        • Gets the current action setting for error/warning events.

                          Returns number

                          The action value (e.g., CONTINUE or EXIT).

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Gets the array of appenders currently registered with the logger.

                          Returns Appender[]

                          An array of Appender instances.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Gets an array of all error and warning log events sent.

                          Returns LogEvent[]

                          An array of LogEvent objects representing error and warning events.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Gets the total number of error log events sent.

                          +
                        • Gets the total number of error log events sent.

                          Returns number

                          The count of error events.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Gets the current log level setting.

                          Returns number

                          The log level value (e.g., OFF, ERROR, WARN, INFO, TRACE). It refers to the level of verbosity to show during the logging process.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Gets the total number of warning log events sent.

                          +
                        • Gets the total number of warning log events sent.

                          Returns number

                          The count of warning events.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Checks if any error or warning log events have been sent.

                          +
                        • Checks if any error or warning log events have been sent.

                          Returns boolean

                          True if at least one error or warning event has been sent; otherwise, false.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Checks if any error log events have been sent.

                          +
                        • Checks if any error log events have been sent.

                          Returns boolean

                          True if at least one error event has been sent; otherwise, false.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Checks if any warning log events have been sent.

                          +
                        • Checks if any warning log events have been sent.

                          Returns boolean

                          True if at least one warning event has been sent; otherwise, false.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Sends an informational log event with the provided message and optional extraFields to all appenders.

                          +
                        • Sends an informational log event with the provided message and optional extraFields to all appenders.

                          Parameters

                          • msg: string

                            The informational message to log.

                          • OptionalextraFields: object

                            Optional structured data (object) to attach to the log event.

                          Returns void

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Removes an appender from the logger, if the resulting array of appenders appender is not empty.

                          +
                        • Removes an appender from the logger, if the resulting array of appenders appender is not empty.

                          Parameters

                          • appender: Appender

                            The Appender instance to remove.

                          Returns void

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Clears the logger's history of error and warning events and resets counters.

                          +
                        • Clears the logger's history of error and warning events and resets counters.

                          Returns void

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Sets the array of appenders for the logger.

                          Parameters

                          • appenders: Appender[]

                            The array of Appender instances to set.

                            -

                          Returns void

                          ScriptError if -- The singleton instance is not available (not instantiated). -- The resulting array doesn't contain unique implementations of Appender. -- appender is null or undefined or has null or undefined elements

                          -
                        • Returns a string representation of the logger's state, including level, action, and message counts.

                          +

                        Returns void

                        ScriptError if:

                        +
                          +
                        • The singleton instance is not available (not instantiated).
                        • +
                        • The resulting array doesn't contain unique implementations of Appender.
                        • +
                        • appender is null or undefined or has null or undefined elements
                        • +
                        +
                        • Returns a string representation of the logger's state, including level, action, and message counts and appenders.

                          Returns string

                          A string describing the logger's current state.

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Sends a trace log event with the provided message and optional extraFields to all appenders.

                          +
                        • Sends a trace log event with the provided message and optional extraFields to all appenders.

                          Parameters

                          • msg: string

                            The trace message to log.

                          • OptionalextraFields: object

                            Optional structured data (object) to attach to the log event.

                          Returns void

                          ScriptError if the singleton instance is not available (not instantiated).

                          -
                        • Sends a warning log event with the provided message and optional extraFields to all appenders.

                          +
                        • Sends a warning log event with the provided message and optional extraFields to all appenders.

                          Parameters

                          • msg: string

                            The warning message to log.

                          • OptionalextraFields: object

                            Optional structured data (object) to attach to the log event.

                            -

                          Returns void

                          ScriptError if -- The singleton instance is not available (not instantiated) -- The logger is configured to exit on critical events.

                          -
                        +

                        Returns void

                        ScriptError if:

                        +
                          +
                        • The singleton instance is not available (not instantiated)
                        • +
                        • The logger is configured to exit on critical events such as warnings and errors.
                        • +
                        +
                        diff --git a/docs/typedoc/types/LayoutFormatter.html b/docs/typedoc/types/LayoutFormatter.html index 5efe079..1bd18b2 100644 --- a/docs/typedoc/types/LayoutFormatter.html +++ b/docs/typedoc/types/LayoutFormatter.html @@ -2,4 +2,4 @@ This is used by appenders to format log events before sending them to output channels.

                        Type declaration

                          • (event: LogEvent): string
                          • Parameters

                            • event: LogEvent

                              The log event to format.

                            Returns string

                            A formatted string representation of the log event.

                            -
                        +
                        diff --git a/docs/typedoc/types/LogEventExtraFields.html b/docs/typedoc/types/LogEventExtraFields.html index aa44283..4aa0174 100644 --- a/docs/typedoc/types/LogEventExtraFields.html +++ b/docs/typedoc/types/LogEventExtraFields.html @@ -2,8 +2,10 @@ It is a plain object with string, number, Date, or function values. Functions are expected to return a string when called. This allows for dynamic content in log events.

                        -

                        Type declaration

                        • [key: string]: string | number | Date | (() => string)
                          +

                        Type declaration

                        • [key: string]: string | number | Date | (() => string)

                        The name of the field.

                        +

                        The value of the field, which can be a string, number, Date, or a function that returns a string.

                        +
                        • Functions should be used for dynamic values that need to be evaluated at the time of logging.
                        • Avoid using complex objects or large data structures to keep log events lightweight.
                        -
                        +
                        diff --git a/docs/typedoc/types/LogEventFactory.html b/docs/typedoc/types/LogEventFactory.html index 9120a6d..1e4bab6 100644 --- a/docs/typedoc/types/LogEventFactory.html +++ b/docs/typedoc/types/LogEventFactory.html @@ -1,5 +1,6 @@ -LogEventFactory | officescripts-logging-framework
                        officescripts-logging-framework
                          Preparing search index...

                          Type Alias LogEventFactory

                          LogEventFactory: (
                              message: string,
                              eventType: LOG_EVENT,
                              extraFields?: LogEventExtraFields,
                          ) => LogEvent

                          Function type for creating a LogEvent. Used in appender implementations.

                          +LogEventFactory | officescripts-logging-framework
                          officescripts-logging-framework
                            Preparing search index...

                            Type Alias LogEventFactory

                            LogEventFactory: (
                                message: string,
                                eventType: LOG_EVENT,
                                extraFields?: LogEventExtraFields,
                            ) => LogEvent

                            Function type for creating a LogEvent. Used in appender implementations.

                            Type declaration

                            +
                          • OptionalextraFields: LogEventExtraFields

                            Optional additional fields for the log event.

                            +
                          • Returns LogEvent

                            A LogEvent object.

                            +
                            diff --git a/package.json b/package.json index dc0aa46..45966c6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "officescripts-logging-framework", - "version": "2.1.3", - "description": "Lightweight, extensible logging framework for Office Scripts, inspired by libraries like Log4j. Enables structured logging via a singleton 'Logger', supporting multiple log levels ('Logger.LEVEL') and pluggable output targets through the 'Appender' interface", + "version": "2.1.4", + "description": "A lightweight, extensible logging framework for Office Scripts(ExcelScript), inspired by frameworks like Log4j. Add robust, structured logs to your Excel scripts with control over log levels, appenders, and error handling.", "main": "index.js", "directories": { "test": "test" diff --git a/src/logger.ts b/src/logger.ts index 6adb3b8..4d69103 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -32,7 +32,7 @@ * Logger.addAppender(ConsoleAppender.getInstance()) * Logger.info("Script started") // Output: [INFO] Script started * ``` - * @remarks Designed and tested for Office Scripts runtime. Extendable with custom appenders via the 'Appender' interface. + * @remarks Designed and tested for Office Scripts and Node.js/TypeScript runtime. Extendable with custom appenders via the 'Appender' interface. * @author David Leal * version 2.1.0 * creation date: 2024-10-01 @@ -45,16 +45,16 @@ /** * Enum representing log event types. * Each value corresponds to a the level of verbosity and is used internally to filter messages. - * `Logger.LEVEL` static constants was implemented in a way to align with the order of the enum + * `LoggerImpl.LEVEL` static constants was implemented in a way to align with the order of the enum * `LOG_EVENT`, so the *order* on how the `LOG_EVENT` values are defined matters. * * Important: - * - If new values are added, update the logic in related classes (e.g. `ExcelAppender`, `Logger`, etc.). - * - Don't start the `LOG_EVENT` enum with `0`, this value is reserved for `Logger.LEVEL` - * for not sending log events (`Logger.LEVEL.OFF`). + * - If new values are added, update the logic in related classes (e.g. `ConsoleAppender`, `ExcelAppender`, `LoggerImpl`, etc.). + * - Don't start the `LOG_EVENT` enum with `0`, this value is reserved for `LoggerImpl.LEVEL` + * for not sending log events (`LoggerImpl.LEVEL.OFF`). * It ensures the verbose level values are aligned with the `LOG_EVENT` enum. - * `Logger.LEVEL` is built based on `LOG_EVENT`, just adding as first value `0`, i.e. - * `Logger.OFF`, therefore the verbosity respects the same order of the `LOG_EVENT`. + * `LoggerImpl.LEVEL` is built based on `LOG_EVENT`, just adding as first value `0`, i.e. + * `LoggerImpl.OFF`, therefore the verbosity respects the same order of the `LOG_EVENT`. * @remarks It was defined as an independent entity since it is used by appenders and by the Logger. */ enum LOG_EVENT { @@ -68,9 +68,10 @@ enum LOG_EVENT { // -------------------- /** - * Function type for creating a LogEvent. Used in appender implementations. + * Function type for creating a `LogEvent`. Used in appender implementations. * @param eventType - The log event type. * @param message - The log message. + * @param extraFields - Optional additional fields for the log event. * @returns A LogEvent object. */ type LogEventFactory = (message: string, eventType: LOG_EVENT, extraFields?: LogEventExtraFields) => LogEvent @@ -79,6 +80,8 @@ type LogEventFactory = (message: string, eventType: LOG_EVENT, extraFields?: Log * It is a plain object with string, number, Date, or function values. * Functions are expected to return a string when called. * This allows for dynamic content in log events. + * @param key - The name of the field. + * @returns The value of the field, which can be a string, number, Date, or a function that returns a string. * @remarks * - Functions should be used for dynamic values that need to be evaluated at the time of logging. * - Avoid using complex objects or large data structures to keep log events lightweight. @@ -174,6 +177,7 @@ interface Layout { * Formats the given log event into its core string representation. * @param event - The log event to format (must be a valid, immutable `LogEvent`). * @returns The formatted string representing the event's core content. The formatted event will be the output of the appender. + * @throws ScriptError if the event is invalid or cannot be formatted. */ format(event: LogEvent): string @@ -194,11 +198,11 @@ interface Layout { * - Convenience logging via `log(msg: string, event: LOG_EVENT)` * - Appenders are responsible for sending log events, not formatting (core formatting is handled by the `Layout` interface). * - Implementations should be stateless or minimize instance state except for tracking the last sent event. - * - Common formatting and event creation concerns (such as layout or logEventFactory) are handled by the `AbstractAppender` base class + * - Common formatting and event creation concerns (such as layout or log event factory) are handled by the `AbstractAppender` base class * and are not part of the interface contract. * - `getLastLogEvent()` is primarily for diagnostics, testing, or error reporting. * - `toString()` must return diagnostic information about the appender and its last log event. - * - Provides to log methods sending a LogEvent object or a message with an event type and optional extra fields. + * - Provides to log methods sending a `LogEvent` object or a message with an event type and optional extra fields. * This allows flexibility in how log events are created and sent. * @see {@link AbstractAppender} for a base class that implements this interface. * @see {@link LogEvent} for the structure of log events. @@ -218,6 +222,7 @@ interface Appender { * @param msg - The message to log. * @param type - The type of log event (from `LOG_EVENT` enum). * @param extraFields - Optional structured data (object) to attach to the log event (e.g., context info, tags). + * @throws ScriptError if the log message is invalid or cannot be delivered. */ log(msg: string, type: LOG_EVENT, extraFields?: object): void @@ -241,6 +246,8 @@ interface Appender { * Provides methods for logging messages, querying log state, managing appenders, and exporting logger state. * Implementations should ensure they should not maintain global mutable state outside the singleton and efficient * log event handling. + * @remarks + * - Usually the `LoggerImpl` implementation should be implemented via *singleton pattern*. * @see {@link LogEvent} for the structure of log events. * @see {@link Appender} for the interface that handles sending log events to output channels. * @see {@link LOG_EVENT} for the enumeration of log event types. @@ -251,9 +258,9 @@ interface Logger { * Sends an error log event with the provided message and optional extraFields to all appenders. * @param msg - The error message to log. * @param extraFields - Optional structured data (object) to attach to the log event. May include metadata, context, etc. - * @throws ScriptError if - * - The singleton instance is not available (not instantiated) - * - The logger is configured to exit on critical events. + * @throws ScriptError if: + * - The singleton instance is not available (not instantiated) + * - The logger is configured to exit on critical events such as warnings and errors. */ error(msg: string, extraFields?: object): void @@ -261,9 +268,9 @@ interface Logger { * Sends a warning log event with the provided message and optional extraFields to all appenders. * @param msg - The warning message to log. * @param extraFields - Optional structured data (object) to attach to the log event. - * @throws ScriptError if - * - The singleton instance is not available (not instantiated) - * - The logger is configured to exit on critical events. + * @throws ScriptError if: + * - The singleton instance is not available (not instantiated) + * - The logger is configured to exit on critical events such as warnings and errors. */ warn(msg: string, extraFields?: object): void @@ -329,20 +336,20 @@ interface Logger { /** * Sets the array of appenders for the logger. * @param appenders - The array of Appender instances to set. - * @throws ScriptError if - * - The singleton instance is not available (not instantiated). - * - The resulting array doesn't contain unique implementations of Appender. - * - appender is `null` or `undefined` or has `null` or `undefined` elements + * @throws ScriptError if: + * - The singleton instance is not available (not instantiated). + * - The resulting array doesn't contain unique implementations of Appender. + * - appender is `null` or `undefined` or has `null` or `undefined` elements */ setAppenders(appenders: Appender[]): void /** * Adds a new appender to the logger. * @param appender - The Appender instance to add. - * @throws ScriptError if - * - The singleton instance is not available (not instantiated). - * - The appender is `null` or `undefined`. - * - The appender is already registered in the logger. + * @throws ScriptError if: + * - The singleton instance is not available (not instantiated). + * - The appender is `null` or `undefined`. + * - The appender is already registered in the logger. * @see {@link Logger.setAppenders} for setting multiple appenders at once and for more details * on the validation of the appenders. */ @@ -383,7 +390,7 @@ interface Logger { reset(): void /** - * Exports the current state of the logger, including level, action, error/warning counts, and critical events. + * Exports the current state of the logger, including level, action, error/warning counts, and critical events (warnings and errors). * @returns An object containing the logger's state. * @throws ScriptError if the singleton instance is not available (not instantiated). */ @@ -396,7 +403,7 @@ interface Logger { } /** - * Returns a string representation of the logger's state, including level, action, and message counts. + * Returns a string representation of the logger's state, including level, action, and message counts and appenders. * @returns A string describing the logger's current state. * @throws ScriptError if the singleton instance is not available (not instantiated). */ @@ -507,6 +514,10 @@ class Utility { * @param funName Used to identify the function name in the error message. * @param context * @throws ScriptError if the log event factory is not a function. + * @remarks + * Identical method already defined in `AbstractAppender` just keep it here in case in the future it can be used + * by other classes that need to validate a log event factory. At this time is not used but the test cases where + * defined for this class in `test/main.ts` so we keep it for potential future use. */ public static validateLogEventFactory( factory: unknown, // or Function, or your specific function type @@ -523,9 +534,8 @@ class Utility { // #region LogEventImpl /** - * Implements the LogEvent interface, providing a concrete representation of a log event. - * It includes properties for the event type, message, and timestamp, along with methods to manage - * the layout used for formatting log events before sending them to appenders. + * 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. * @remarks * - 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. @@ -560,7 +570,6 @@ class LogEventImpl implements LogEvent { * - 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. */ constructor(message: string, type: LOG_EVENT, extraFields?: LogEventExtraFields, timestamp: Date = new Date(), ) { @@ -717,7 +726,7 @@ class LogEventImpl implements LogEvent { * Default implementation of the `Layout` interface. * Formats log events into a string using a provided or default formatting function. * @remarks - * - Uses the Strategy Pattern for extensibility: you can pass a custom formatting function (strategy) to the constructor. + * - Uses the *Strategy Pattern* for extensibility: you can pass a custom formatting function (strategy) to the constructor. * - All events are validated to conform to the `LogEvent` interface before formatting. * - Throws `ScriptError` if the event does not conform to the expected `LogEvent` interface. * @see {@link Layout} for the interface definition. @@ -742,34 +751,42 @@ class LayoutImpl implements Layout { private readonly _formatter: LayoutFormatter /** - * Constructs a new `LayoutImpl`. - * - * @param formatter - Optional. A function that formats a `LogEvent` as a string. - * If not provided, a default formatter is used: `[timestamp] [type] message`. - * The formatter function synchronous and must accept a single `LogEvent` - * parameter and return a string. - * - * @remarks Strategy Pattern to allow flexible formatting via formatter function. - * Pass a custom function to change the formatting logic at runtime. - * @throws ScriptError if: - * - The formatter is not a function or does not have the expected arity (`1` parameter). - * - The formatter is `null` or `undefined`. - * - The instance object is `undefined` or `null` (if subclassed or mutated in ways that break the interface). - * @example - * // Using the default formatter: - * const layout = new LayoutImpl() - * // Using a custom formatter for JSON output: - * const jsonLayout = new LayoutImpl(event => JSON.stringify(event)) - * // Using a formatter for XML output: - * const xmlLayout = new LayoutImpl(event => - * `${event.type}${event.message}` - * ) - * // Using a shorter format [type] [message]: - * const shortLayout = new LayoutImpl(e => `[${LOG_EVENT[e.type]}] ${e.message}`) - * // Using a custom formatter with a named function, so in toString() shows the name of the formatter. - * let shortLayoutFun: Layout = new LayoutImpl( - * function shortLayoutFun(e:LogEvent):string{return `[${LOG_EVENT[e.type]}] ${e.message}`}) - */ + * Constructs a new `LayoutImpl` with an optional custom formatter. + * + * @param formatter - (Optional) A function that formats a `LogEvent` as a string. + * If omitted, uses the default formatter: `[timestamp] [type] message`. + * The formatter must accept a single `LogEvent` parameter, and return a string. + * + * @remarks + * - Implements the *Strategy Pattern*: pass a custom formatter to change output format at runtime. + * - Formatter must be a function of arity 1; see {@link LayoutFormatter}. + * - Throws `ScriptError` if the formatter is invalid or the instance is misconfigured. + * + * @throws ScriptError if: + * - The formatter is not a function or does not accept exactly one argument. + * - The formatter is `null` or `undefined`. + * - The instance is `null` or `undefined` (e.g., due to subclassing or mutation). + * + * @example + * // Default formatter: + * const layout = new LayoutImpl() + * + * // Custom JSON formatter: + * const jsonLayout = new LayoutImpl(event => JSON.stringify(event)) + * + * // XML formatter: + * const xmlLayout = new LayoutImpl(event => + * `${event.type}${event.message}` + * ) + * + * // Short format: [type] message + * const shortLayout = new LayoutImpl(e => `[${LOG_EVENT[e.type]}] ${e.message}`) + * + * // Named function for better diagnostics in toString(): + * const namedShortLayout = new LayoutImpl( + * function shortLayoutFun(e: LogEvent): string { return `[${LOG_EVENT[e.type]}] ${e.message}` } + * ) + */ constructor(formatter?: LayoutFormatter) { this._formatter = formatter ?? LayoutImpl.defaultFormatterFun LayoutImpl.validateLayout(this as LayoutImpl, "LayoutImpl.constructor") @@ -806,19 +823,17 @@ class LayoutImpl implements Layout { } /** - * Asserts that the provided object implements the Layout interface. + * Asserts that the provided object implements the `Layout` interface. * Checks for the public `format` method (should be a function taking one argument). - * Also validates the internal `_formatter` property if present, by calling `validateFormatter`. - * Used by appenders to validate layout objects at runtime. + * It used by `LayoutImpl` and appenders to ensure that the layout is valid before using it. * - * @param layout - The object to validate as a Layout implementation. + * @param layout - The object to validate as a `Layout` implementation. * @param context - (Optional) Additional context for error messages. * @throws ScriptError if: * - layout is `null` or `undefined`. * - format is not a function or doesn't have arity `1`. - * - _formatter is present and is missing, not a function, or doesn't have arity `1`. */ - static validateLayout(layout: Layout, context?: string) { + public static validateLayout(layout: Layout, context?: string) { const PREFIX = context ? `[${context}]: ` : "[LayoutImpl.validateLayout]: " if (!layout || typeof layout !== "object") { throw new ScriptError(PREFIX + "Invalid Layout: layout object is null or undefined") @@ -835,16 +850,16 @@ class LayoutImpl implements Layout { } /** - * Validates that the provided value is a valid formatter function - * for use in LayoutImpl (`_formatter` property). The formatter must be - * a function accepting a single LogEvent argument and must return a non-empty, non-`null` string. + * Validates the provided value is a valid formatter function + * for use in `LayoutImpl` (`_formatter` property). The formatter must be + * a function accepting a single `LogEvent` argument and must return a non-empty, non-`null` string. * * @param formatter - The candidate formatter function to validate. * @param context - (Optional) Additional context for error messages. * @throws ScriptError if formatter is missing, not a function, doesn't have arity `1`, * or returns `null`/empty string for a sample event. */ - static validateFormatter(formatter: LayoutFormatter, context?: string) { + private static validateFormatter(formatter: LayoutFormatter, context?: string) { const PREFIX = context ? `[${context}]: ` : "[LayoutImpl.validateFormatter]: " if (typeof formatter !== "function" || formatter.length !== 1) { throw new ScriptError( @@ -919,22 +934,31 @@ LayoutImpl.defaultFormatterFun = Object.freeze(function defaultLayoutFormatterFu // #region AbstractAppender /** * Abstract base class for all log appenders. - * This class defines shared utility methods to standardize log formatting, - * label generation, and event validation across concrete appender implementations. + * Provides a common interface and shared functionality for concrete appender implementations. * - * It relies on a `LogEventFactory` function to create log events, enabling flexible - * and customizable event creation strategies. The `LogEventFactory` is validated on - * construction to ensure it meets the expected signature. This design allows users - * to supply custom event creation logic if needed. - * - * Appenders such as `ConsoleAppender` and `ExcelAppender` should extend this class - * to inherit consistent logging behavior and event creation via the `LogEventFactory`. + * Features: + * - Allows specifying the formatting of log events via a shared `Layout` (see {@link Layout}). + * - Uses a static `LogEventFactory` function type to create log events, enabling flexible and customizable event creation. + * - Implements the core logic for logging, delegating the actual delivery of log events to subclasses via the `sendEvent` method. + * + * Usage: + * - Extend this class to implement specific appenders (e.g., `ConsoleAppender`, `ExcelAppender`). + * - Subclasses **must implement** the `sendEvent(event, context)` method to define how log events are delivered. + * + * @remarks + * - The static layout and log event factory are shared across all appenders. + * - Designed for extensibility and consistency across different output targets. + * + * @see {@link LOG_EVENT} for the enumeration of log event types. + * @see {@link LogEvent} for the structure of log events. + * @see {@link Layout} for the layout used to format log events before sending them to appenders. + * @see {@link LayoutImpl} for the default layout implementation. * @see {@link Appender} for the interface definition. * @see {@link LogEventFactory} for the factory function type used to create log events. - * @see {@link Layout} for the layout used to format log events before sending them to appenders. + */ abstract class AbstractAppender implements Appender { - // Default factory function to create LogEvent instances, if was not set before. + /**Default factory function to create `LogEvent` instances. Used in case it was not set before by the user.*/ public static defaultLogEventFactoryFun: LogEventFactory // Static layout shared by all events private static _layout: Layout | null = null @@ -996,7 +1020,7 @@ abstract class AbstractAppender implements Appender { /** * Sets the layout associated to all events, the layout is assigned only if it was not set before. * @param layout - The layout to set. - * @throws ScriptError if the layout is not a valid Layout implementation. + * @throws ScriptError if the layout is not a valid `Layout` implementation. */ public static setLayout(layout: Layout): void { const CONTEXT = "AbstractAppender.setLayout" @@ -1007,20 +1031,22 @@ abstract class AbstractAppender implements Appender { } /** - * Log a message or log event. + * 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. * @param arg1 - `LogEvent` or message string. - * @param arg2 - `LOG_EVENT`, only required if `arg1` is a string. + * @param arg2 - `LOG_EVENT` type. Only required if `arg1` is a string. * @param arg3 - `extraFields`, only used if `arg1` is a string. * @throws ScriptError if: - * - `arg1` is a string but `arg2` is not provided or is not a valid `LOG_EVENT`. - * - `arg1` is not a valid `LogEvent`. - * - The log event factory is not set or is not a valid function. + * - `arg1` is a string but `arg2` is not provided or is not a valid `LOG_EVENT`. + * - if the `arg1` is not a string and `arg1` is not a valid `LogEvent`. * @remarks - * - If `arg1` is a string, it creates a new `LogEvent` using the provided message and event type. + * - If `arg1` is a string, it creates a new `LogEvent` using the provided message and event type, and if presents `extraFields`. * - If `arg1` is already a `LogEvent`, it validates the event and sends it directly. * - The method uses the static layout to format the log event before sending it to the appenders. - * - The `arg3` parameter is optional and can be used to provide additional fields for the log event. - * - It relays on abstract method `sendEvent` to send the log event to the appropriate destination. + * - The `arg3` parameter is optional and can be used to provide extra fields to create a log event, if `arg1` is a string. + * - The *Template pattern* is used, i.e. it implements common logic for logging, but delegates the actual sending of the log event + * to the `sendEvent` abstract method. Therefore subclasses must implement the `sendEvent` method to define how the log event is sent. * @example * ```ts * // Example: Log an error message with a custom event type and extra fields. @@ -1032,7 +1058,6 @@ abstract class AbstractAppender implements Appender { * ``` * @override */ - public log(arg1: LogEvent | string, arg2?: LOG_EVENT, arg3?: LogEventExtraFields): void { const CONTEXT = `AbstractAppender.log` const PREFIX = `[${CONTEXT}]: ` @@ -1059,7 +1084,7 @@ abstract class AbstractAppender implements Appender { // #TEST-ONLY-START /** Sets to `null` the static layout, useful for running different scenarios. * @remarks Mainly intended for testing purposes. The state of the singleton will be lost. - * This method only exist in `src` folder, it won't be deployed in `dist` folder (production). + * This method is available only in `src` folder, it is not deployed in `dist` folder (production). */ public static clearLayout(): void { AbstractAppender._layout = null // Force full re-init @@ -1069,7 +1094,7 @@ abstract class AbstractAppender implements Appender { // #TEST-ONLY-START /** Sets to `null` the log event factory, useful for running different scenarios. * @remarks Mainly intended for testing purposes. The state of the singleton will be lost. - * This method only exist in `src` folder, it won't be deployed in `dist` folder (production). + * This method is available only in `src` folder, it is not deployed in `dist` folder (production). */ public static clearLogEventFactory(): void { AbstractAppender._logEventFactory = null // Force full re-init @@ -1077,9 +1102,9 @@ abstract class AbstractAppender implements Appender { // #TEST-ONLY-END /** - * Returns a string representation of the appender. - * It includes the information from the base class plus the information of the current class, + * 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. * @returns A string representation of the appender. * @override */ @@ -1094,8 +1119,8 @@ abstract class AbstractAppender implements Appender { /** * Send the log event to the appropriate destination. - * This method must be implemented by subclasses to define how the log event is sent. - * It is responsible for sending the log event to the appropriate destination (e.g., console, file, etc.). + * 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.). * @param event - The log event to be sent. * @param context - (Optional) A string to provide additional context in case of an error. * @throws ScriptError if @@ -1104,10 +1129,10 @@ abstract class AbstractAppender implements Appender { protected abstract sendEvent(event: LogEvent, context?: string): void /** - * Send the log event to the appropriate destination. + * Set the last log event sent to the appender. * @param event - The log event to be sent. - * @throws ScriptError if - * - The event is not a valid `LogEvent`. + * @throws ScriptError if: + * - The event is not a valid `LogEvent`. * @remarks * Subclasses **must** call `setLastLogEvent(event)` after successfully sending the event, * otherwise `getLastLogEvent()` will not reflect the most recent log event. @@ -1119,9 +1144,10 @@ abstract class AbstractAppender implements Appender { } // #TEST-ONLY-START - /**To ensure when invoking clearInstance in a sub-class it also clear (`null`) the last log event. + /**To ensure when invoking `clearInstance` method in a sub-class it also clears (`null`) the last log event + * sent to the appender. * @remarks Mainly intended for testing purposes. The state of the singleton will be lost. - * This method only exist in `src` folder, it won't be deployed in `dist` folder (production). + * This method is available only in `src` folder, it is not deployed in `dist` folder (production). */ protected clearLastLogEvent(): void { this._lastLogEvent = null @@ -1170,18 +1196,22 @@ AbstractAppender.defaultLogEventFactoryFun = Object.freeze( // #region ConsoleAppender /** - * Singleton appender that logs messages to the console. It is used as default appender, + * Singleton appender that logs messages to the console. It is used as default appender by this class and by `LoggerImpl`, * if no other appender is defined. The content of the message event sent can be customized via * any `Layout` implementation, but by default it uses the `LayoutImpl`. * Usage: * - Call `ConsoleAppender.getInstance()` to get the appender * - Automatically used if no other appender is defined * Warning: The console appender is a singleton, so it should not be instantiated multiple times. - * @example: + * @example * ```ts - * // Add console appender to the Logger - * Logger.addAppender(ConsoleAppender.getInstance()) + * const appender = ConsoleAppender.getInstance() // Get the singleton instance + * appender.log("This is an info message", LOG_EVENT.INFO) // Log an info message + * // Better use: + * Logger.info("This is an info message") // uses the ConsoleAppender by default. * ``` + * @see {@link LOG_EVENT} for the log event types used to determine the color of the message. + * @see {@link LogEvent} for the structure of log events. * @see {@link Appender} for the interface definition. * @see {@link AbstractAppender} for the base class documentation. * @see {@link Layout} for the layout used to format log events before sending them to the console. @@ -1197,7 +1227,9 @@ class ConsoleAppender extends AbstractAppender implements Appender { super() // Call the parent constructor without layout } - /**Override `toString` method. Show the last message event sent. + /**Override `toString` method. It uses the parent `toString` method to get the base information, + * such as the layout and last log event sent to the appender. + * @returns A string representation of the appender, including the class name, since it doesn't have additional properties. * @throws ScriptError If the singleton was not instantiated */ public toString(): string { @@ -1231,7 +1263,7 @@ class ConsoleAppender extends AbstractAppender implements Appender { * appender.getLastLogEvent().message // Output: "" * ``` * @remarks Mainly intended for testing purposes. The state of the singleton will be lost. - * This method only exist in `src` folder, it wont be deployed in `dist` folder (production). + * This method is available only in `src` folder, it is not deployed in `dist` folder (production). */ public static clearInstance(): void { if (ConsoleAppender._instance) { @@ -1242,12 +1274,12 @@ class ConsoleAppender extends AbstractAppender implements Appender { // #TEST-ONLY-END /** - * Protected method to send the event to the console. At this point is where the event is formatted before sending it to the console. + * Send the log event to the console. At this point is where the event is formatted before sending it to the console. * @param event - The log event to output. * @param context - (Optional) A string to provide additional context in case of an error. - * @throws ScriptError if - * The event is not a valid `LogEvent`. - * The instance is not available (not instantiated). + * @throws ScriptError if + * - The event is not a valid `LogEvent`. + * - The instance is not available (not instantiated). * @override */ protected sendEvent(event: LogEvent, context?: string): void { @@ -1283,15 +1315,23 @@ class ConsoleAppender extends AbstractAppender implements Appender { /** * Singleton appender that logs messages to a specified Excel cell. * Logs messages in color based on the `LOG_EVENT` enum: - * - `ERROR`: red, `WARN`: orange, `INFO`: green, `TRACE`: gray (defaults can be customized) + * - `ERROR`: red, `WARN`: orange, + * `INFO`: green, `TRACE`: gray + * - Such colors can be customized by the user + * * Usage: - * - Must call `ExcelAppender.getInstance(range)` once with a valid single cell range - * - range is used to display log messages - * Warning: The Excel appender is a singleton, so it should not be instantiated multiple times. + * - Must call `ExcelAppender.getInstance(ExcelScript.Range)` once with a valid single cell range. + * - The range is used to display log messages. * @example * ```ts - * const range = workbook.getWorksheet("Log").getRange("A1") - * Logger.addAppender(ExcelAppender.getInstance(range)) // Add appender to the Logger + * const range = workbook.getActiveWorksheet().getRange("A1") + * const appender = ExcelAppender.getInstance(range) + * appender.log("This is an info message", LOG_EVENT.INFO) // Log an info message + * // Better use: + * const logger = LoggerImpl.getInstance(LoggerImpl.LOG_LEVEL.INFO) + * logger.addAppender(appender) // Add the Excel appender to the logger + * logger.info("This is an info message") + * ``` * @remarks * - The appender requires a single cell range to display log messages. @@ -1301,19 +1341,18 @@ class ConsoleAppender extends AbstractAppender implements Appender { * - The appender is a singleton, so it should not be instantiated multiple times. * - The appender uses a private constructor to prevent user instantiation, and the instance is created via the static `getInstance` method. * - The appender validates the input range and colors when creating the instance. + * @see {@link LOG_EVENT} for the log event types used to determine the color of the message. + * @see {@link LogEvent} for the structure of log events. * @see {@link Appender} for the interface definition. * @see {@link AbstractAppender} for the base class documentation. - * @see {@link LogEvent} for the structure of log events. * @see {@link Layout} for the layout used to format log events before sending them to Excel. - - * @see {@link ConsoleAppender} for an example of a console appender that logs messages to the console. + * @see {@link ConsoleAppender} Another implementation of the `Appender` interface that logs messages to the console. */ class ExcelAppender extends AbstractAppender implements Appender { /** * Default colors for log events, used if no custom colors are provided. - * These colors are defined as hex strings (without the `#` prefix). * The colors can be customized by passing a map of `LOG_EVENT` types to hex color strings - * when calling getInstance(). Default colors are: + * when calling `getInstance()`. Default colors are: * - `ERROR`: `9c0006` red * - `WARN`: `ed7d31` orange * - `INFO`: `548235` green @@ -1367,6 +1406,7 @@ class ExcelAppender extends AbstractAppender implements Appender { /** * Returns the Excel range where log messages are written. + * This range must be a single cell, and it is used to display log messages. * @returns The `ExcelScript.Range` object representing the message cell range. * @remarks This is the cell where log messages will be displayed. */ @@ -1379,21 +1419,29 @@ class ExcelAppender extends AbstractAppender implements Appender { * On first call, requires a valid single cell Excel range to display log messages and optional * color customizations for different log events (`LOG_EVENT`). Subsequent calls ignore parameters * and return the existing instance. - * @param msgCellRng - Excel range where log messages will be written. Must be a single cell and + * @param msgCellRng - ExcelScript.Range where log messages will be written. Must be a single cell range and * not `null` or `undefined`. * @param eventFonts - Optional. A map of `LOG_EVENT` types to hex color codes for the font colors. * If not provided, defaults to the predefined colors in `DEFAULT_EVENT_FONTS`. * The user can provide just the colors they want to customize, - * the rest will use the default colors. + * the rest will use the default colors. These colors can be defined with or without `#` prefix. * @returns The singleton `ExcelAppender` instance. - * @throws ScriptError if `msgCellRng` was not defined or if the range covers multiple cells - * or if it is not a valid Excel range. - * if the font colors are not valid hexadecimal values for colors + * @throws ScriptError if: + * - `msgCellRng` was not defined or if the range covers multiple cells + * - It is not a valid Excel range or the range doesn't represent a single cell. + * - The font colors are not valid hexadecimal values for colors * @example * ```ts * const range = workbook.getWorksheet("Log").getRange("A1") - * const excelAppender = ExcelAppender.getInstance(range) - * ExcelAppender.getInstance(range, "ff0000") // ignored if called again + * let excelAppender = ExcelAppender.getInstance(range) + * excelAppender.log("info event", LOG_EVENT.INFO) + * // Example using custom colors for errors events for the rest it uses the default colors: + * const customFonts: Record = { + * [LOG_EVENT.ERROR]: "0000FF", // blue + * } + * excelAppender.clearInstance() // Clear the singleton instance + * excelAppender = ExcelAppender.getInstance(range, customFonts) + * excelAppender.log("custom colored error event", LOG_EVENT.ERROR) // Output: In cell A1 with blue color: "custom colored error event" * ``` * @see {@link ExcelAppender.DEFAULT_EVENT_FONTS} */ @@ -1448,14 +1496,14 @@ class ExcelAppender extends AbstractAppender implements Appender { * const activeSheet = workbook.getActiveWorksheet() // workbook is input argument of main * const msgCellRng = activeSheet.getRange("C2") * appender = ExcelAppender.getInstance(msgCellRng) // with default log event colors - * appender.info("info event") // Output: In Excel in cell C2 with green color shows: "info event" + * appender.log("info event", LOG_EVENT.INFO) // Output: In cell C2 with green color: "info event" * // Now we want to test how getInstance() can throw a ScriptError, * // but we can't because the instance was already created and it is a singleton we need clearInstance * appender.clearInstance() * appender = ExcelAppender.getInstance(null) // throws a ScriptError * ``` * @remarks Mainly intended for testing purposes. The state of the singleton will be lost. - * This method only exist in `src` folder, it wont be deployed in `dist` folder (production). + * This method is available only in `src` folder, it is not deployed in `dist` folder (production). * */ public static clearInstance(): void { @@ -1467,7 +1515,8 @@ class ExcelAppender extends AbstractAppender implements Appender { // #TEST-ONLY-END /** - * Shows instance configuration plus last message sent by the appender + * Shows instance configuration plus the message cell range address, the event fonts used, plus the parent information provided by `toString` method. + * @returns A string representation of the appender. * @throws ScriptError, if the singleton was not instantiated. */ public toString(): string { @@ -1487,7 +1536,10 @@ class ExcelAppender extends AbstractAppender implements Appender { * Sets the value of the cell, with the event message, using the font defined for the event type, * if not font was defined it doesn't change the font of the cell. * @param event a value from enum `LOG_EVENT`. - * @throws ScriptError in case event is not a valid `LOG_EVENT` enum value. + * @param context (Optional) A string to provide additional context in case of an error. + * If not provided, it uses the class name and method name as context. + * @throws ScriptError In case event is not a valid `LogEvent`. + * @override */ protected sendEvent(event: LogEvent, context?: string): void { @@ -1568,21 +1620,26 @@ class ExcelAppender extends AbstractAppender implements Appender { // #region LoggerImpl /** * Singleton class that manages application logging through appenders. - * Supports the following log events: `ERROR`, `WARN`, `INFO`, `TRACE` (`LOG_EVENT` enum). - * Supports the level of information (verbose) to show via `Logger.LEVEL`: `OFF`, `ERROR`, `WARN`, `INFO`, `TRACE`. - * If the level of information (`LEVEL`) is `OFF`, no log events will be sent to the appenders. - * Supports the action to take in case of `ERROR`, `WARN` log events: the script can - * continue (`Logger.ACTION.CONTINUE`), or abort (`Logger.ACTION.EXIT`). Such actions only take effect - * if the `LEVEL` is not `Logger.LEVEL.OFF`. - * Allows defining appenders, controlling the channels the events are sent to. - * Collects error/warning sent by the appenders via `getCriticalEvents()`. - * + * - Supports the following log events: `ERROR`, `WARN`, `INFO`, `TRACE` (`LOG_EVENT` enum). + * - Supports the level of information (verbose) to show via `LoggerImpl.LEVEL`: `OFF`, `ERROR`, `WARN`, `INFO`, `TRACE`, + * where `WARN` is the default maximum level of verbosity. + * - If the level of information (`LEVEL`) is `OFF`, no log events will be sent to the appenders. + * - Supports the action to take in case of `ERROR`, `WARN` log events: the script can + * continue (`LoggerImpl.ACTION.CONTINUE`), or abort (`LoggerImpl.ACTION.EXIT` default). Such actions only take effect + * if the `LEVEL` is not `LoggerImpl.LEVEL.OFF`. + * - Allows defining appenders, controlling the channels the events are sent to. + * - Collects error/warning sent by the appenders via `getCriticalEvents()`. + * * Usage: - * - Initialize with `Logger.getInstance(level, action)`. - * - Add one or more appenders (e.g. `ConsoleAppender`, `ExcelAppender`) + * - Initialize with `LoggerImpl.getInstance(level, action)`. + * - Add one or more appenders (e.g. `ConsoleAppender`, `ExcelAppender`), via `addAppender()` for example. * - Use `logger.error()`, `logger.warn()`, `logger.info()`, or `logger.trace()` to log. * * Features: + * - Supports multiple appenders, allowing logs to be sent to different destinations (e.g., console, Excel). + * - If when invoking any log method (e.g. `logger.error()`) if the singleton was not instantiated, + * it does a lazy initialization of the logger with default configuration, + * i.e. `LoggerImpl.LEVEL=WARN` and `LoggerImpl.ACTION=EXIT`. * - If no appender is added, `ConsoleAppender` is used by default. * - Logs are routed through all registered appenders. * - Collects a summary of error/warning messages and counts. @@ -1592,7 +1649,7 @@ class ExcelAppender extends AbstractAppender implements Appender { * @example * ```ts * // Minimal logger usage; ConsoleAppender is auto-added if none specified - * LoggerImpl.getInstance().info("This message will appear in the console by default. + * LoggerImpl.getInstance().error("This message will appear in the console by default.") * ``` * @see {@link Logger} for the interface definition. * @see {@link Appender} for the interface definition of the appenders @@ -1603,14 +1660,24 @@ class ExcelAppender extends AbstractAppender implements Appender { class LoggerImpl implements Logger { // Constants - /** Static constant (enum pattern) for log event types. */ + /** Static 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. + */ public static readonly ACTION = Object.freeze({ CONTINUE: 0, // In case of error/warning log events, the script continues EXIT: 1, // In case of error/warning log event, throws a ScriptError error } as const) /** Static 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 */ + 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. + @see {@link LOG_EVENT} for the log event types used to determine the color of the message. + */ public static readonly LEVEL = Object.freeze(Object.assign({ OFF: 0 }, LOG_EVENT)) // Attributes @@ -1677,8 +1744,8 @@ class LoggerImpl implements Logger { /** * Returns the level of verbosity allowed in the Logger. The levels are incremental, i.e. - * it includes all previous levels. For example: `Logger.WARN` includes warnings and errors since - * `Logger.ERROR` is lower. + * it includes all previous levels. For example: `LoggerImpl.LEVEL.WARN` includes warnings and errors since + * `LoggerImpl.LEVEL.ERROR` is lower. * @returns The current log level. * @throws ScriptError If the singleton was not instantiated. * @override @@ -1702,11 +1769,11 @@ class LoggerImpl implements Logger { /** * Sets the array of appenders with the input argument appenders. * @param appenders Array with all appenders to set. - * @throws ScriptError If the singleton was not instantiated, - * if appenders is `null` or `undefined`, or contains - * `null` or `undefined` entries, - * or if the appenders to add are not unique - * by appender class. See JSDoc from {@link LoggerImpl.addAppender} for more details. + * @throws ScriptError If: + * - The singleton was not instantiated. + * - appenders is `null` or `undefined`, or contains `null` or `undefined` entries. + * - The appenders to add are not unique + * by appender class. See JSDoc from {@link LoggerImpl.addAppender} for more details. * @override */ public setAppenders(appenders: Appender[]) { @@ -1719,10 +1786,10 @@ class LoggerImpl implements Logger { /** * Adds an appender to the list of appenders. * @param appender The appender to add. - * @throws ScriptError If the singleton was not instantiated, - * if the input argument is `null` or `undefined`, - * or if it breaks the class uniqueness of the appenders. - * All appenders must be from a different implementation of the `Appender` class. + * @throws ScriptError If: + * - The singleton was not instantiated, + * - The input argument is `null` or `undefined`, + * - It breaks the class uniqueness of the appenders. All appenders must be from a different implementation of the `Appender` class. * @override * @see {@link LoggerImpl.setAppenders} */ @@ -1739,33 +1806,34 @@ class LoggerImpl implements Logger { } /** - * Returns the singleton Logger instance, creating it if it doesn't exist. + * Returns 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. * @remarks Subsequent calls ignore these parameters and return the existing instance. - * @param level The verbosity level (default: `Logger.LEVEL.WARN`). Controls verbosity. + * @param level 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 - * `Logger.LEVEL.OFF`, which suppresses all messages sent to the appenders. - * For example: `Logger.LEVEL.INFO` allows sending errors, warnings, and information events, + * `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. - * @param action The action on error/warning (default: `Logger.ACTION.EXIT`). + * @param action The action on error/warning (default: `LoggerImpl.ACTION.EXIT`). * Determines if the script should continue or abort. - * If the value is `Logger.ACTION.EXIT`, throws a `ScriptError` exception, - * i.e. aborts the Script. If the action is `Logger.ACTION.CONTINUE`, the - * script continues. It only takes effect if the level is not `Logger.LEVEL.OFF`. + * 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`. * @returns The singleton Logger instance. - * @throws ScriptError If the level input value was not defined in `Logger.LEVEL` or it doesn't - * match the `LOG_EVENT` enum values in the specified order. - * If the action input value was not defined in `Logger.ACTION`. + * @throws ScriptError If: + * - The level input value was not defined in `LoggerImpl.LEVEL` or it doesn't + * match the `LOG_EVENT` enum values in the specified order. + * - The action input value was not defined in `LoggerImpl.ACTION`. * @example * ```ts * // Initialize logger at INFO level, continue on errors/warnings - * const logger = Logger.getInstance(Logger.LEVEL.INFO, Logger.ACTION.CONTINUE) + * const logger = Logger.getInstance(LoggerImpl.LEVEL.INFO, LoggerImpl.ACTION.CONTINUE) * // Subsequent calls ignore parameters, return the same instance - * const sameLogger = Logger.getInstance(Logger.LEVEL.ERROR, Logger.ACTION.EXIT) + * 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 Logger.LEVEL value: INFO + * logger.trace("Step one") // Doesn't send because of LoggerImpl.LEVEL value: INFO * ``` */ public static getInstance( @@ -1799,15 +1867,16 @@ class LoggerImpl implements Logger { /** * 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 `Logger.LEVEL.ERROR` to send this event to the appenders. + * 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. * @param msg - The error message to log. * @param extraFields - Optional structured data to attach to the log event (e.g., context info, tags). * @remarks * If no singleton was defined, it does lazy initialization with default configuration. * If no appender was defined, it does lazy initialization to `ConsoleAppender`. - * @throws ScriptError If level is greater than `Logger.LEVEL.OFF` and the action is `Logger.ACTION.EXIT`. - * If any internal error occurs while sending the event to the appenders. + * @throws ScriptError If: + * - Level is greater than `LoggerImpl.LEVEL.OFF` and the action is `LoggerImpl.ACTION.EXIT`. + * - If any internal error occurs while sending the event to the appenders. */ public error(msg: string, extraFields?: LogEventExtraFields): void { this.log(msg, LOG_EVENT.ERROR, extraFields) @@ -1815,16 +1884,16 @@ class LoggerImpl implements Logger { /** * 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 `Logger.LEVEL.WARN` to send this event to the appenders. + * 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. * @param msg - The warning message to log. * @param extraFields - Optional structured data to attach to the log event (e.g., context info, tags). - * @throws ScriptError If level is greater than `Logger.LEVEL.ERROR` and the action is `Logger.ACTION.EXIT`. - * If any internal error occurs while sending the event to the appenders. + * @throws ScriptError If: + * - Level is greater than `LoggerImpl.LEVEL.ERROR` and the action is `LoggerImpl.ACTION.EXIT`. + * - Any internal error occurs while sending the event to the appenders. * @remarks - * If no singleton was defined, it does lazy initialization with default configuration. - * If no appender was defined, it does lazy initialization to `ConsoleAppender`. - + * - If no singleton was defined, it does lazy initialization with default configuration. + * - If no appender was defined, it does lazy initialization to `ConsoleAppender`. */ public warn(msg: string, extraFields?: LogEventExtraFields): void { this.log(msg, LOG_EVENT.WARN, extraFields) @@ -1832,13 +1901,13 @@ class LoggerImpl implements Logger { /** * 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 `Logger.LEVEL.INFO` to send this event to the appenders. + * The level has to be greater than or equal to `LoggerImpl.LEVEL.INFO` to send this event to the appenders. * @param msg - The informational message to log. * @param extraFields - Optional structured data to attach to the log event (e.g., context info, tags). * @throws ScriptError If any internal error occurs while sending the event to the appenders. * @remarks - * If no singleton was defined, it does lazy initialization with default configuration. - * If no appender was defined, it does lazy initialization to `ConsoleAppender`. + * - If no singleton was defined, it does lazy initialization with default configuration. + * - If no appender was defined, it does lazy initialization to `ConsoleAppender`. */ public info(msg: string, extraFields?: LogEventExtraFields): void { this.log(msg, LOG_EVENT.INFO, extraFields) @@ -1846,13 +1915,13 @@ class LoggerImpl implements Logger { /** * 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 `Logger.LEVEL.TRACE` to send this event to the appenders. + * The level has to be greater than or equal to `LoggerImpl.LEVEL.TRACE` to send this event to the appenders. * @param msg - The trace message to log. * @param extraFields - Optional structured data to attach to the log event (e.g., context info, tags). * @throws ScriptError If any internal error occurs while sending the event to the appenders. * @remarks - * If no singleton was defined, it does lazy initialization with default configuration. - * If no appender was defined, it does lazy initialization to `ConsoleAppender`. + * - If no singleton was defined, it does lazy initialization with default configuration. + * - If no appender was defined, it does lazy initialization to `ConsoleAppender`. */ public trace(msg: string, extraFields?: LogEventExtraFields): void { this.log(msg, LOG_EVENT.TRACE, extraFields) @@ -1934,8 +2003,8 @@ class LoggerImpl implements Logger { * Returns the label for a log action value. * @param action - The log action to get the label for. * @returns The label for the action. - * If `action` is `undefined`, returns the label for the current logger instance's action. - * If neither is set, returns `UNKNOWN`. + * - If `action` is `undefined`, returns the label for the current logger instance's action. + * - If neither is set, returns `UNKNOWN`. * @example * ```ts * LoggerImpl.getActionLabel(LoggerImpl.ACTION.CONTINUE) // Returns "CONTINUE" @@ -1955,8 +2024,8 @@ class LoggerImpl implements Logger { /** * Returns the label for the given log level. * @returns The label for the log level. - * If `level` is `undefined`, returns the label for the current logger instance's level. - * If neither is set, returns `UNKNOWN`. + * - If `level` is `undefined`, returns the label for the current logger instance's level. + * - If neither is set, returns `UNKNOWN`. * @example * ```ts * LoggerImpl.getLevelLabel(LoggerImpl.LEVEL.INFO) // Returns "INFO" @@ -1975,6 +2044,8 @@ class LoggerImpl implements Logger { /** * @returns A string representation of the logger instance. + * `toString()` includes the logger's level, action, error count, warning count, + * and a list of appenders with their string representations. * @throws ScriptError If the singleton was not instantiated. * @override */ @@ -1993,9 +2064,10 @@ class LoggerImpl implements Logger { return `${NAME}: {${scalarInfo}, appenders: ${appendersString}}` } - /**Short version fo the `toString()` which exludes the appenders details. + /**Short version of the `toString()` which excludes the appenders details. * @returns Similar to `toString`, but showing the list of appenders name only. * @throws ScriptError If the singleton was not instantiated. + * @see {@link LoggerImpl.toString} for more details. */ public toShortString(): string { const CONTEXT = `${LoggerImpl.name}.toString` @@ -2014,9 +2086,9 @@ class LoggerImpl implements Logger { // #TEST-ONLY-START /** - * Sets the singleton instance to `null`, useful for running different scenarios. + * Sets the singleton instance to `null`, useful for running different scenarios and testing purposes. * @remarks Mainly intended for testing purposes. The state of the singleton will be lost. - * This method only exist in `src` folder, it won't be deployed in `dist` folder (production). + * 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. * @throws ScriptError If the singleton was not instantiated. * @example @@ -2025,11 +2097,11 @@ class LoggerImpl implements Logger { * // 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 = Logger.getInstance() // LEVEL: WARN, ACTION: EXIT + * 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: Logger.LEVEL:WARN, Logger.ACTION:CONTINUE - * Logger.clearInstance() // Clear the singleton - * logger = Logger.getInstance(LEVEL.WARN, ACTION.CONTINUE) + * // 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) * ``` */