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

nestjs-logger-roarr

v1.1.0

Published

Roarr integration for NestJS Logging (compatible with ConsoleLogger and LoggerService)

Downloads

19

Readme

Quickstart

Install

pnpm install nestjs-logger-roarr

Setup

NOTE Do not forget to set ROARR_LOG=true otherwise you will see no log messages!

To use the same logger for lower level NestJS code and your own:

import { RoarrLoggerService } from nestjs-logger-roarr';
import { AppModule } from "app.module";

const logger = RoarrLoggerService.sharedInstance();
const app = await NestFactory.create(AppModule, { logger });

As you might expect, calling RoarrLoggerService.sharedInstance() multiple times returns the same Service.

If you'd like to use the module directly:

import { Module } from '@nestjs/common';
import { RoarrLoggerModule } from 'nestjs-logger-roarr;

@Module({
  imports: [
    RoarrLoggerModule.forRoot(),
  ],
})
export class AppModule {}

Note that by importing the module, the lower level NestJS code will use a possibly different logger, while your AppModule will use RoarrLoggerModule. See the previously mentioned .sharedInstance() if you want all logged code to use the RoarrLoggerService.

If you'd like to do build the logger service asynchronously (for example to inject some options):

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config;
import { RoarrLoggerService } from 'nestjs-logger-roarr;

@Module({
  imports: [
    RoarrLoggerService.forRootAsync({
      imports: [ ConfigModule ],
      useFactory: async (cfg:ConfigService) => ({
        logLevel: 'debug',
        environment: cfg.get('ENVIRONMENT') ?? 'staging',
        ctx: { // Context that is set @ the top level
          appName: cfg.get('APP_NAME'),
        },
      }),
    })
  ]
})

export class AppModule {}

Usage

You can use it from any place Injectables are welcome:

import { Injectable } from '@nestjs/common';
import { RoarrLoggerService } from 'nestjs-logger-roarr;

@Injectable()
export class AppService {
  public constructor(@Inject() private readonly logger: RoarrLoggerService) {}
}

You can use RoarrLoggerService just like the build in Logger via a property in Injectables:

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

@Injectable()
class MyService {
  private readonly logger = new Logger(MyService.name);

  doSomething() {
    this.logger.log('Doing something...');
  }
}

Note that RoarrLoggerService extends ConsoleLoggerService (which extends LoggerService), so you can use it anywhere the other interfaces are expected/required.

FAQ

What will log messages look like?

In an example application, the usual startup logs look like this:

{"context":{"in":"NestFactory","logLevel":30,"pid":2225063},"message":"Starting Nest application...","sequence":"0","time":1681023672355,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"DBModule dependencies initialized","sequence":"1","time":1681023672368,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"OpenTelemetryModule dependencies initialized","sequence":"2","time":1681023672368,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"OpenTelemetryCoreModule dependencies initialized","sequence":"3","time":1681023672369,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"ConfigHostModule dependencies initialized","sequence":"4","time":1681023672376,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"ConfigModule dependencies initialized","sequence":"5","time":1681023672376,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"AppModule dependencies initialized","sequence":"6","time":1681023672376,"version":"2.0.0"}
{"context":{"in":"RoutesResolver","logLevel":30,"pid":2225063},"message":"AppController {/}:","sequence":"7","time":1681023672389,"version":"2.0.0"}
{"context":{"in":"RouterExplorer","logLevel":30,"pid":2225063},"message":"Mapped {/, GET} route","sequence":"8","time":1681023672390,"version":"2.0.0"}
{"context":{"in":"NestApplication","logLevel":30,"pid":2225063},"message":"Nest application successfully started","sequence":"9","time":1681023672392,"version":"2.0.0"}
{"context":{"in":"AppService","logLevel":30,"pid":2225063},"message":"running getHello!!!","sequence":"10","time":1681023676282,"version":"2.0.0"}

Contributing

Contributions are always welcome!

  1. Fork this repository
  2. Create your feature/bugfix/etc branch (git checkout -b feat/my-branch)
  3. Commit any changes to your branch
  4. Run (and add) tests to ensure yoru changes work
  5. Open a pull request

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements