npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mayunaikwadi/nestlogify

v0.0.7

Published

NestLogify is a highly customizable and versatile logger module designed for NestJS, offering seamless integration with both Pino and Winston logging libraries. It empowers developers to implement structured and efficient logging within their NestJS appli

Downloads

132

Readme

NestLogify

Node.js version NPM version License

NestLogify is a highly customizable and versatile logger module designed for NestJS, offering seamless integration with both Pino and Winston logging libraries. It empowers developers to implement structured and efficient logging within their NestJS applications, enhancing observability and debugging with minimal effort. The module operates based on two key parameters: logProvider, which specifies the provider ('pino' or 'winston'), and logExporter, which determines how logs are exported ('file', 'console', or 'both'), making it a flexible solution for advanced log management.

Table of Contents

Features

  • Supports two popular logging libraries: Pino and Winston.
  • Configurable logging destinations (console, files).
  • Daily log rotation for file logs.
  • Simple integration into NestJS applications.
  • Type-safe logger interface.

Installation

To install the package, run the following command:

npm install @mayunaikwadi/nestlogify

Usage

To use the logger in your NestJS application, follow these steps:

Importing the Logger Module Import the LoggerModule in your application's main module (e.g., AppModule).

import { Module } from '@nestjs/common';
import { LoggerModule } from '@mayunaikwadi/nestlogify';

@Module({
  imports: [
    // Use 'winston' for Winston logger and logExporter - 'file' | 'console' | 'both'
    LoggerModule.forRoot({ logProvider : 'pino', logExporter : 'both' }),  
  ],
})
export class AppModule {}

Injecting the Logger Service

You can inject the logger service into your services or controllers.

import { Inject, Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  constructor(@Inject('LOGGER_SERVICE') private logger) {}

  getHello(): string {
    this.logger.log('Hello World logged');
    return 'Hello World!';
  }
}

Configuration

You can configure the logger module by passing either 'pino' or 'winston' as a parameter to forRoot()

Examples

Pino Logger Example

import { Module } from '@nestjs/common';
import { LoggerModule } from '@mayunaikwadi/nestlogify';

@Module({
  imports: [
    // Set the logExporter value to either 'file', 'console', or 'both'.
    LoggerModule.forRoot({ logProvider : 'pino', logExporter : 'both' }),  
  ],
})
export class AppModule {}

Winston Logger Example

import { Module } from '@nestjs/common';
import { LoggerModule } from 'nestlogify';

@Module({
  imports: [
    // Set the logExporter value to either 'file', 'console', or 'both'.
    LoggerModule.forRoot({ logProvider : 'winston', logExporter : 'both' }),  
  ],
})
export class AppModule {}

Logging Messages in Services

Here’s how to use the logger in a service:

import { Inject, Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  constructor(@Inject('LOGGER_SERVICE') private logger) {}

  performAction(): void {
    this.logger.log('Performing an action...');
    // Log an error
    this.logger.error('An error occurred');
    // Log a warning
    this.logger.warn('This is a warning');
  }
}

API Reference

Logger Module LoggerModule.forRoot({ logProvider : 'winston', logExporter : 'both' }),: Initializes the logger module with the specified logger type.

Logger Parameters

  • logProvider : LoggerProvider; - This property specifies the provider name. It should be set to either 'pino' or 'winston'.
  • logExporter : LogExporter - This property determines the way logs are exported. Set the value to either 'file', 'console', or 'both'.

Logger Interface

The logger interface supports the following methods:

  • log(message: string): void: Logs an informational message.
  • error(message: string): void: Logs an error message.
  • warn(message: string): void: Logs a warning message.
  • info(message: string): void: Logs a generic informational message.
  • debug(message: string): void: Logs a debug message
  • verbose(message: string): void: Logs a verbose message

License

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

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any feature requests or bugs.