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

@nolawnchairs/nest-logger

v1.4.0

Published

In-house NestJS logging extension

Downloads

5

Readme

NestJS Logger

This is an in-house tool for extending the NestJS logger to include file logging.

Not supported for general use.

Versions 1.2.x

This attempted to implement deferred evaluation of the log message, but it was so incompatible with the native NestJS logger that it was abandoned. Ensure your version is >= 1.3

Usage

Bootstrap

Add the logger to the Nest bootstrap function

import { NestFactory } from '@nestjs/core'
import { LoggerService, NEST_LOGGER } from '@nolawnchairs/nest-logger'
import { AppModule } from './app.module'

async function bootstrap() {

  // Buffer logs so Nest bootstrapping log events will be applied to our logger
  const app = await NestFactory.create(AppModule, { bufferLogs: true })

  // Get the logger using the NEST_LOGGER token
  const logger = app.get<LoggerService>(NEST_LOGGER)

  // Set the logger instance
  app.useLogger(logger)

  await app.listen(3000)
  logger.log('Application has started')
}

Import to the AppModule

Add the LoggerModule to your AppModule imports:

import { LoggerModule } from '@nolawnchairs/nest-logger'

@Module({
  imports: [
    LoggerModule.forRoot({
      // The default context if one is not provided
      defaultContext: 'Main',
      profiles: {
        // File logging
        file: {
          // Full path to the log file
          filename: '/var/log/app.log',
          // Logging level. This prints only errors and warnings
          level: ['warn', 'error'],
        },
        stdout: {
          // Logging Level. This prints ALL log levels
          level: 'VDIWE',
        },
      },
    }),
  ]
})
export class AppModule { }

Configuring Levels

Log levels can be expressed as an array of NestJS LogLevel strings:

['verbose', 'debug', 'log', 'warn', 'error']

Or as our shorthand, with the desired levels as a single string:

V: Verbose
D: Debug
I: Info (Log)
W: Warn
E: Error

Note that we abbreviate the log level as I instead of L, as we believe the term log poorly describes the level.

Usage with Injection

import { Injectable } from '@nestjs/common'
import { Logger, LoggerService } from '@nolawnchairs/nest-logger'

@Injectable()
export class AppService {

  constructor(
    @Logger(AppService) private readonly logger: LoggerService) { }

  test() {
    this.logger.log('This is an info-level message')
  }
}

Caveats

The logging methods in the default implementation of NestJS's ConsoleLogger all have a context argument used to override the logging context (in our case the name of the logger instance). With all NestJS logger calls, the LAST argument provided will override the context if it's a string.