Ts.ED Logger

website·Indexed 33 days ago

https://logger.tsed.dev/

A multi-channel logger for Node.js and TypeScript that supports multiple destinations including Console, File, RabbitMQ, Slack, Seq, LogStash, and Loggly. It features configurable log rolling based on file size or date, a variety of built-in layouts (JSON, Pattern, Colored, Basic), and support for custom appenders and layouts.

Tokens
9.9K
Snippets
59
Records
76
Agent score
56%

What's inside Ts.ED Logger

  1. Overview of Ts.ED Logger capabilities

    Ts.ED Logger is a multi-channel logger for Node.js, Bun.js, and browser applications. It is designed to be extensible and allows logging to the console, files, and remote services via a plugin system consisting of Appenders and Layouts.
  2. Overview of the Ts.ED Framework

    Ts.ED is a framework designed for building scalable, maintainable, and highly testable server-side applications in a Node.js environment. It leverages TypeScript, Object-Oriented Programming (OOP) via classes, decorators, and functional programming patterns to structure applications.

    Ts.ED provides a high-level abstraction layer via its Platform API but allows developers to access the underlying framework APIs directly, ensuring compatibility with the broader ecosystem of third-party Node.js modules.

  3. Configure multi-channel logging destinations

    The logger supports sending logs to multiple destinations simultaneously, including the Console, Remote servers, and Files. When logging to files, the system supports configurable log rolling based on either file size or date to manage disk space and log rotation.
  4. Install the Insight Appender for @tsed/logger

    To send log events to a Rapid7 Insight server using @tsed/logger, install the @tsed/logger-insight package.
    npm install --save @tsed/logger-insight
  5. Use StdoutAppender and StdErrAppender in @tsed/logger v8

    StdoutAppender and StdErrAppender have been moved from the core package to a separate package called @tsed/logger-std. You must install this package to continue using these appenders.
    npm install @tsed/logger-std
    # or
    yarn add @tsed/logger-std
    import { StdoutAppender, StdErrAppender } from "@tsed/logger-std";
  6. Install and configure the Seq Appender for Ts.ED

    The Seq Appender allows you to send log events from a Ts.ED application to a Seq server. It requires the @tsed/seq package and is configured within the logger's appenders settings.
    npm install --save @tsed/seq
  7. Configure log appenders in Ts.Logger

    Appenders in Ts.Logger are used to serialize log events to specific outputs, such as the console (stdout/stderr), files, emails, or network destinations. Each appender is defined by a type and can be configured with specific log levels to filter which events are written to that output.
    import {Logger} from "@tsed/logger";
    
    const logger = new Logger("loggerName");
    
    logger.appenders
      .set({
        type: "stdout",
        level: ["debug", "info", "trace"]
      })
      .set({
        type: "stderr",
        level: ["error", "fatal", "warn"]
      })
      .set({
        type: "file",
        filename: "logfile.log"
      });
  8. Install LogStash UDP Appender for Ts.ED Logger

    The logstash-udp appender allows sending log events to a Logstash server using Node.js core UDP support, requiring no additional system dependencies. To ensure the UDP socket is closed cleanly, call logger.shutdown when the application terminates.
    npm install --save @tsed/logger-logstash-udp
  9. Install and setup SMTP Appender for @tsed/logger

    The SMTP Appender sends log events as emails. To ensure all pending emails are sent before the application exits, you must call logger.shutdown when the application closes.
    npm install @tsed/logger
    npm install @tsed/logger-smtp
  10. Configure log appenders in Ts.Logger

    Appenders in Ts.Logger are responsible for serializing log events to specific outputs, such as files, emails, or network destinations. Each appender is defined by a type which determines the output destination. You can chain multiple appenders using the logger.appenders.set() method to route different log levels to different destinations.
    import {Logger} from "@tsed/logger";
    
    const logger = new Logger("loggerName");
    
    logger.appenders
      .set({
        type: "stdout",
        level: ["debug", "info", "trace"]
      })
      .set({
        type: "stderr",
        level: ["error", "fatal", "warn"]
      })
      .set({
        type: "file",
        filename: "logfile.log"
      });