Interface LoggerStream<StreamType>

Type Parameters

  • StreamType extends Pick<NodeJS.WritableStream, "write"> | Logger = Pick<NodeJS.WritableStream, "write"> | Logger

Hierarchy

  • LoggerStream

Properties

allowPinnedLines?: boolean

Whether or not to write pinned lines to this stream.

Default

true

interceptData?: ((data: unknown[], level: string) => undefined | null | unknown[])

Type declaration

    • (data: unknown[], level: string): undefined | null | unknown[]
    • This function will be used to intercept and possibly modify log data.

      If the function returns X, then the log data will Y:

      • undefined - the log message will be logged as normal. This does the same thing as returning the unmodified data array.
      • array - will be replaced with the returned data. The returned array will not be intercepted again, the formatted message, however, will.
      • null - will not be logged at all

      Example

      options = {
      intercept: (data) => {
      if (data[0] instanceof Error) {
      return ["Intercepted Error: " + data[0].message];
      }
      }
      };

      logger.log([1, 2]);
      // => [1, 2]
      logger.log(new Error("Test Error"));
      // => Intercepted Error: Test Error

      Parameters

      • data: unknown[]
      • level: string

      Returns undefined | null | unknown[]

interceptString?: ((data: string, level: string) => undefined | null | string)

Type declaration

    • (data: string, level: string): undefined | null | string
    • This function will be used to intercept and possibly modify log messages.

      This is different than interceptData, because the logger will format the log data first and then pass the resulting string to this.

      If the function returns X, then the log message will Y:

      • undefined - the log message will be logged as normal. This does the same thing as returning the unmodified string.
      • string - will be replaced with the returned string. The returned array will not be intercepted again.
      • null - will not be logged at all

      Parameters

      • data: string
      • level: string

      Returns undefined | null | string

level?: string | number | ((importance: number) => boolean)

Determines the verbosity of the output.

Example

options = {
level: (importance) => importance >= 1 && importance <= 2, // Importance values between INFO and WARN
};

logger.debug("Some really detailed information");
// No output.
logger.info("Something just happened!");
// -> Something just happened!
logger.warn("This should be fixed though...");
// -> This should be fixed though
logger.error("Something went horribly wrong!!!");
// No output.
prefix?: ((level: string) => string)

Type declaration

    • (level: string): string
    • The prefix function that will be used to format the log message.

      This is applied after interceptString is called.

      If the stream is a Logger instance, this function will not be called.

      Parameters

      • level: string

      Returns string

stream: StreamType

Stream that will be used to output the log messages. If the stream is a Logger instance, the output will be logged to the stream. without filtering and without a prefix.

Generated using TypeDoc