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

@betsys-nestjs/logger

v6.0.1

Published

This library is responsible for all logging in this monorepo. It supports HTTP action logging and nodejs cluster logging (using process messaging). In the background it uses [Winston logger](https://www.npmjs.com/package/winston).

Downloads

7

Readme

Logger library

This library is responsible for all logging. It supports HTTP (expres) and grpc action logging and nodejs cluster logging (using process messaging). In the background it uses Winston logger.

Logger level priorities

We are using npm levels from the winston itself (the lower the number higher the priority is):

    error: 0,
    warn: 1,
    info: 2,
    http: 3,
    verbose: 4,
    debug: 5,
    silly: 6

Environment variables

This library requires next ENV variables:

| Variable name | Description | |----------------------------|-------------------------------------------------------------------------------------------------| | CONFIG_LOG_LEVEL | Logger levels with lower priority will be skipped | | CONFIG_LOG_FORMAT=simple | Logger format logstash or simple (value logstash will format logs in kibana friendly way) |

Dependencies

| Package | Version | | --------------------------- | ------- | | on-headers | ^1.0.2 | | winston | ^3.3.3 | | @betsys-nestjs/config-utils | ^2.0.0 | | @hapi/joi | ^17.1.1 | | @nestjs/common | ^10.0.0 | | @nestjs/config | ^3.0.0 | | @nestjs/core | ^10.0.0 | | express | ^4.17.1 | | reflect-metadata | ^0.1.12 | | rxjs | ^7.1.0 |

Usage

To start using this library simply import LoggerModule to your main application module.

import {DATA_RETRIEVER, LoggerModule, DataRetrieverService, ContextTypeEnum} from '@betsys-nestjs/logger';
import {ExpressDefaultDataRetrieverService} from "./express-default-data-retriever.service";

@Module({
    imports: [
        LoggerModule.forRoot('express', {
            provide: DATA_RETRIEVER,
            useClass: ExpressDefaultDataRetrieverService,
        }),
    ]
})
class AppModule {
}

You can define whether you want to use express or grpc in forRoot method. For all platforms there are default data retrievers that are responsible for getting data to log from Request and Response objects based on platform. This can be specified as second parameter of forRoot method and you can add any providers you need to inject to module.

DATA_RETRIVER is defined in provider array and creates a provider with this token. This should be a service that inherits from exposed interface DataRetriever.

For express you can use:

{
    provide: DATA_RETRIEVER, 
    useClass: ExpressDefaultDataRetrieverService,
}

For grpc you can use:

{
    provide: DATA_RETRIEVER, 
    useClass: GrpcDefaultDataRetrieverService,
}

Then inject Logger provider wherever you want to log something.

import {LoggerModule} from '@betsys/logger';

class AppService {
    constructor(private readonly logger: Logger) {
    }
}

If you for some reason do not trust dependency resolver without providing annotation, you can use @InjectLogger() to provide explicit logger token.

import {InjectLogger, Logger} from '@betsys/logger';

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

Exclude actions from HTTP logging

If you want to exclude any actions from HTTP logging you can mark them using @LoggerExclude().

import {LoggerExclude} from '@betsys/logger';

@Controller()
export class CatsController {

    @LoggerExclude()
    @Get()
    public getHello(): string {
    }
}

Or you can mark whole controllers.

import {LoggerExclude} from '@betsys/logger';

@LoggerExclude()
@Controller()
export class CatsController {
}