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

@opengeekslab_llc/nest-custom-logger

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opengeekslab_llc/nest-custom-logger

Logger that prints to output json logs

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

nest-custom-logger

Provides logger and request middleware for NestJS and express application.

Output examples

Styled Example

Logs

Styled Example

Http logs

Styled Example

Json Example

Logs

Json Example

Http logs
{"type":"http","context":"Request","message":"::ffff:192.168.88.107 - POST /auth/signin - 400 [Bad Request] (0b sent in 21 ms)","requestData":{"clientIp":"::ffff:192.168.88.107","method":"POST","originalUrl":"/auth/signin","statusCode":400,"statusMessage":"Bad Request","contentSize":0,"responseTime":21}}

Usage

Simple usage

import { Logger } from '@opengeekslab_llc/nest-custom-logger';

const logger = new (Logger(!process.env.NODE_ENV))('Hello');
logger.log('World')

Usage in classes

function CustomLogger(context: string) {
  return new (Logger(!process.env.NODE_ENV))(context);
}

class Test {
  logger = CustomLogger('Test');

  run() {
    this.logger.log('log');
    this.logger.error('error');
  }
}

Usage for not ts projects

const { Logger } = require('@opengeekslab_llc/nest-custom-logger');

const logger = new (Logger(!process.env.NODE_ENV))('Hello');
logger.log('World')

Usage of middleware for express

const express = require('express');
const { requestLoggerMiddleware } = require('@opengeekslab_llc/nest-custom-logger');
const app = express();

const requestWriteLogs = CustomLogger('Request');

const requestLogger = requestLoggerMiddleware({
    writeLog: requestWriteLogs.http,
});

app.use(requestLogger);

Real usage

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { CustomLogger, requestLogger } from '@opengeekslab_llc/nest-custom-logger';

const port = 8000;

async function bootstrap() {
  const logger = CustomLogger('NEST');

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

  // use this middleware to show http logs in your console
  app.use(requestLogger);

  await app.listen(port);

  logger.log(`app is listening on port ${port}`);
}

bootstrap();

Keywords

FAQs

Package last updated on 25 Jan 2022

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