1.0.0-alpha.2 • Published 2 years ago

nestjs-serilog-like-logger v1.0.0-alpha.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

NestJS Serilog-Like Logger

This logger for NestJS is designed to provide a logging experience similar to Serilog, with a format and style inspired by NestJS's built-in console-logger.service.ts and the Serilog logging framework. It supports various log levels and outputs structured logs in a clear, readable format.

Features

  • Log levels based on Serilog's structure, providing a range of verbosity from Verbose to Fatal.
  • Integration with NestJS, allowing for seamless use within any NestJS application.
  • Structured logging, providing detailed context and service information.

Output Example

The logger outputs JSON formatted logs. An example log entry might look like this:

{"Level":"Information","Message":"Starting Nest application...","Timestamp":"2023-12-06T22:36:10.672Z","Service":"demo-api-service","SourceContext":"NestFactory"}

Installation

To install the nestjs-serilog-like-logger, run:

npm install nestjs-serilog-like-logger

or

yarn add nestjs-serilog-like-logger

Usage

To use the logger in your NestJS application:

import { NestjsSerilogLikeLogger } from 'nestjs-serilog-like-logger';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: new NestjsSerilogLikeLogger('demo-api-service'),
  });

  await app.listen(3000);
}

bootstrap();

This will configure your NestJS application to use the NestjsSerilogLikeLogger for all its logging needs.

Log Event Levels

The logger supports the following log event levels, inspired by Serilog:

  • Verbose: Detailed information about the flow through the system.
  • Debug: Information useful for debugging.
  • Information: General operational entries about what's happening inside the application.
  • Warning: Indications of possible issues or service degradation.
  • Error: Errors and exceptions that cannot be handled.
  • Fatal: Critical errors causing complete failure of the application.

Contributing

Contributions to the nestjs-serilog-like-logger are welcome. Please submit any issues or pull requests through the project's GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.