Options
All
  • Public
  • Public/Protected
  • All
Menu

Class to handle logging processes for an application. Can be customized to include logs of a specific
LogLevelType to a log file as desired.


Creating an instance of the LogService with the default configurations.

const logger = new LogService("My Logged Event");
logger.debug("This won't be included when the logger is flushed");
logger.info("But this will!");
logger.warn("So will this!");
logger.success(); // Signals end of logging and writes to the log file

Creating an instance of the LogService with includeLogsOfLevel as a LogLevelType.

const logger =
new LogService("My Logged Event", { includeLogsOfLevel: LogLevelType.DEBUG });
// This is included in the log file since includedLogsOfLevel is set to
// LogLevelType.DEBUG
logger.debug("Hello world!");

Creating an instance of the LogService with includeLogsOfLevel as a string.

const logger =
new LogService("My Logged Event", { includeLogsOfLevel: "debug" });
// This is included in the log file since includedLogsOfLevel is set to
// the string value of 'debug.' Note for JavaScript users, this is not
// case-sensitive, but for TypeScript users, this looks for the strings
// in lowercase form.
logger.debug("Hello world!");

Creating an instance of the LogService with a specified workingDirectory.

const logger =
new LogService("My Logged Event", { workingDirectory: "test/directory" }
// Creates the log file at ./test/directory/logs/YYYY-MM.txt.
logger.success();

Hierarchy

  • LogService

Index

Constructors

constructor

  • Creates an instance of the LogService.


    Note: This service creates a text file when either the success or fatal methods are
    called, which is placed a logs directory of the current working directory with the name format of
    YYY-MM.txt. It is recommended to either use the
    ProcessUtil.setCurrentWorkingDirectory in your main script file to control where the log files are
    placed.

    Parameters

    • eventName: string

      The name of the event that generated the LogService. This is included at the
      start of a log message when the log file is built.

    Returns LogService

  • Creates an instance of the LogService.


    Note: The LogService creates a log text file when eiter the success or fatal
    methods are called which is placed in a log directory with the file format of YYYY-MM.txt. In
    order to ensure that the log directory is placed as desired, it is recommended to use
    ProcessUtil.setCurrentWorkingDirectory in your main script file. It is also possible to provide a value
    using the options.workingDirectory value.

    Parameters

    • eventName: string

      The name of the event that generated the
      LogService. This is included at the start of a log message when the log file is built.

    • options: LoggerServiceOptions

      An object containing some additional
      configuration options to customize the LogService's behavior. If any option is left out, it is initialized
      to a default value.

    Returns LogService

  • Creates an instance of the LogService.


    Note: The LogService creates a log text file when eiter the success or fatal
    methods are called which is placed in a log directory with the file format of YYYY-MM.txt. In
    order to ensure that the log directory is placed as desired, it is recommended to use
    ProcessUtil.setCurrentWorkingDirectory in your main script file. It is also possible to provide a value
    using the options.workingDirectory value.

    Parameters

    • eventName: string

      The name of the event that generated the
      LogService. This is included at the start of a log message when the log file is built.

    • options: LoggerServiceOptions

      An object containing some additional
      configuration options to customize the LogService's behavior. If any option is left out, it is initialized
      to a default value.

    Returns LogService

Methods

debug

  • debug(...args: any[]): void

error

  • error(...args: any[]): void

fatal

  • fatal(...args: any[]): void
  • Adds fatal error content to the logger. Terminates the logger afterwords.

    Parameters

    • Rest ...args: any[]

      The content to log at the fatal level.

    Returns void

getEventName

  • getEventName(): string
  • Getter method for the logger's event name.

    Returns string

    The name of the event that created this instance of the LogService.

getLogFilePath

  • getLogFilePath(): string
  • Getter method for the logger's log file path.

    Returns string

    The file path for where the LogService will put the file once it has finished logging.

getLogs

getLogsOfLevel

  • Returns all the log entries in the LogService of a specified log level.

    Parameters

    • logLevel: LogLevelType

      The log level to search the logger for.

    Returns LogEntry[]

    An array of all the log entries matching the specified log level.

getLogsOfLevelOrHigher

  • Returns all the log entries in the logger that are of the specified log level or higher. Priority is
    as follows:

    • Debug
    • Info
    • Warn
    • Error
    • Fatal

    Parameters

    • logLevel: LogLevelType

      The log level to search the logger for.

    Returns LogEntry[]

    An array of all the log entries matching or greater than the specified log level.

getParentDirectory

  • getParentDirectory(): string
  • Getter method for the logger's parent directory path.

    Returns string

    The file path for where the LogService will place the logs directory.

getStartTime

  • getStartTime(): Date

info

  • info(...args: any[]): void

success

  • success(): void
  • Indicates that the process resolved successfully. Logs a success message, and then flushes the
    logger's log entries array afterwords.

    Returns void

warn

  • warn(...args: any[]): void

Generated using TypeDoc