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.
What's inside Ts.ED Logger
- 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.
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.
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.Install the Insight Appender for @tsed/logger
To send log events to a Rapid7 Insight server using @tsed/logger, install the@tsed/logger-insightpackage.npm install --save @tsed/logger-insightUse 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-stdimport { StdoutAppender, StdErrAppender } from "@tsed/logger-std";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/seqpackage and is configured within the logger's appenders settings.npm install --save @tsed/seqConfigure 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 atypeand 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" });Install LogStash UDP Appender for Ts.ED Logger
Thelogstash-udpappender 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, calllogger.shutdownwhen the application terminates.npm install --save @tsed/logger-logstash-udpInstall 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 calllogger.shutdownwhen the application closes.npm install @tsed/logger npm install @tsed/logger-smtpConfigure 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 atypewhich determines the output destination. You can chain multiple appenders using thelogger.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" });Install the TSed File Logger appender
To use the file appender for writing log events to a file, install the@tsed/logger-filepackage.npm install --save @tsed/logger-fileInstall @tsed/logger
Install the @tsed/logger package along with typescript and source-map-support to begin logging in your project.npm install -g typescript npm install @tsed/logger npm install source-map-support