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

1.5.1 • Public • Published

Bunyan Logger Service

NestJS LoggerService that uses Bunyan.

Installation

npm i @nest-toolbox/bunyan-logger

Example

You can pass any custom stream supported by Bunyan

import { NestFactory } from '@nestjs/core';
import { BunyanLoggerService } from "@nest-toolbox/bunyan-logger";
import { AppModule } from './app.module';
const Elasticsearch = require('bunyan-elasticsearch');

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(
    ApplicationModule,
    {
      logger: new BunyanLoggerService({
        projectId: 'project',
        formatterOptions: {
          outputMode: 'long',
        },
      }),
    },
  );

  const esStream = new Elasticsearch({
    type: 'logs',
    host: 'localhost:9300',
  });

  const app = await NestFactory.create<NestExpressApplication>(
    ApplicationModule,
    {
      logger: new BunyanLoggerService({
        projectId: 'project',
        formatterOptions: {
          outputMode: 'long',
        },
        extraFields?: {
          environment:'production',
          microservice: 'users',
        };
        customStreams: [
          { stream: esStream },
          {
            path: 'foo.log',
          },
        ],
      }),
    },
  );

  await app.listen(3000);
}
bootstrap();

BunyanLoggerService constructor options

check https://github.com/thlorenz/bunyan-format

options: {
    projectName: string;
    formatterOptions: {
      outputMode: string;
      color?: boolean;
      levelInString?: boolean;
      colorFromLevel?: any;
    };
    customStreams?: any[];
    extraFields?: {
      [key: string]: string;
    };
}

Package Sidebar

Install

npm i @nest-toolbox/bunyan-logger

Weekly Downloads

68

Version

1.5.1

License

MIT

Unpacked Size

91.6 kB

Total Files

10

Last publish

Collaborators

  • lupu60