Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-logger-service

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-logger-service

Nest Json LoggerService implementation.

  • 1.0.16
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
988
decreased by-8.01%
Maintainers
1
Weekly downloads
 
Created
Source

json-logger-service

Provides a Json Nest LoggerService.

Installation

$ npm i json-logger-service --save

Usage

Nest Json LoggerService implementation use

Configuring Nest to use a custom Json LoggerService.

import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import {JsonLoggerService} from 'json-logger-service';

const bootstrap = async () => {
    const app = await NestFactory.create(AppModule);
    app.useLogger(new JsonLoggerService('NestServer'));
    await app.listen(3000);
};
bootstrap();

Using a new Json logger in your classes

import {JsonLogger, LoggerFactory} from 'json-logger-service';

export class HelloWorldService {
    private readonly logger: JsonLogger = LoggerFactory.createLogger(HelloWorldService.name);

    public getHello(): string {
        this.logger.info('Hello World!');
        this.logger.info({myContextProperty: 'My property\'s value', anotherProperty: 'Another value'}, 'Hello World with some context!');
        return 'Hello World!';
    }
}

Use Express request logger

Configuring Nest to use a simple Express request logger.

import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import {RequestLogger} from 'json-logger-service';

const bootstrap = async () => {
    const app = await NestFactory.create(AppModule);
    ...
    app.use(RequestLogger.buildExpressRequestLogger());
    ...
    await app.listen(3000);
};
bootstrap();

Considering a request to /mypath, the logger output should be something like:

{"name":"RequestLogger","hostname":"HOSTNAME","pid":PID,"level":30,"msg":"Before request GET '/mypath'","time":"2019-12-09T12:10:23.020Z","v":0}
{"name":"RequestLogger","hostname":"HOSTNAME","pid":PID,"level":30,"msg":"After request GET '/mypath'","time":"2019-12-09T12:10:23.021Z","v":0}

An array of base paths you don't want to log (for security or GDPR reasons maybe) can be passed in the RequestLogger constructor.

app.use(RequestLogger.buildExpressRequestLogger(['/my-path-with-sensible-information']));

Then, considering a request to /my-path-with-sensible-information/customerEmail@gmail.com, the logger output should be something like:

{"name":"RequestLogger","hostname":"HOSTNAME","pid":PID,"level":30,"msg":"Before request GET 'Path Omitted'","time":"2019-12-09T12:10:23.020Z","v":0}
{"name":"RequestLogger","hostname":"HOSTNAME","pid":PID,"level":30,"msg":"After request GET 'Path Omitted'","time":"2019-12-09T12:10:23.021Z","v":0}

Keywords

FAQs

Package last updated on 09 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc