@implicity/nest-logger
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Nest Logger

Implicity flavored logger for Nest.js service

Install

npm install --save @implicity/nest-logger

Usage

Nest.js logger: main.ts

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

const serviceLogger = new Logger();
async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: serviceLogger
  });

  await app.listen(process.env.SERVICE_PORT);
}

bootstrap()
  .catch((e) => {
    serviceLogger.handleError(e);
    process.exit(1);
  });

Route logger: app.module.ts

import { APP_INTERCEPTOR } from '@nestjs/core';
import { LoggingInterceptor } from '@implicity/nest-logger';


@Module({
  imports: [],
  controllers: [],
  providers: [{
    provide: APP_INTERCEPTOR,
    useClass: LoggingInterceptor  }]
})
export class AppModule {}

Using the static instance:

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

Logger.info('This is a log message');
Logger.info({
    message: 'This is a log message with meta !',
    meta: 'toto',
    context: 'MyController'
});

Instancing a logger instance:

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

const myLoggerWithMeta = new Logger({
    myMeta: 'lol'
});
myLoggerWithMeta.info('This is a log message');
myLoggerWithMeta.info({
    message: 'This is a log message with meta !',
    meta: 'toto',
    context: 'MyController'
});

Readme

Keywords

none

Package Sidebar

Install

npm i @implicity/nest-logger

Weekly Downloads

3

Version

0.0.5

License

ISC

Unpacked Size

624 kB

Total Files

12

Last publish

Collaborators

  • julien-sarazin
  • mguedj