Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with structured logging - Seq #229

Open
olakara opened this issue Sep 2, 2021 · 0 comments
Open

Issue with structured logging - Seq #229

olakara opened this issue Sep 2, 2021 · 0 comments
Assignees

Comments

@olakara
Copy link

olakara commented Sep 2, 2021

Describe the bug
When using Seq logging (I am using the package bunyan-seq to create a custom stream) The string interpolation / variable substitution does not work

To Reproduce
Steps to reproduce the behavior:

  1. Include bunyan-seq package to your project along with @nest-toolbox/bunyan-logger
  2. Setup the logging service as mentioned below in the main.ts
  3. In the controller's create an instance of Logger from @nestjs/common
  4. call the logger methods as described below and see the results

Expected behavior
When logging with the following statement:
this.logger.warn('{user} tried access the {service} service with an expired key!',{ user: 'E73882', service: 'PurchaseOrder'});
the output in the log should be
E73882 tried access the PurchaseOrder service with an expired key!

image

Screenshots
What happens is:

image

Additional context
Here is my main.ts:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

const seq = require('bunyan-seq');

async function bootstrap() {
  const app = await NestFactory.create(AppModule,{
    bufferLogs: true,
  });

  app.useLogger(new BunyanLoggerService({      
        projectId: 'NestJS-Microservice',
        formatterOptions: {
          outputMode: 'json',
        },
        customStreams:[seq.createStream({serverUrl: 'http://localhost:5341', apiKey: '123456789'})]  ,
        extraFields: {
          app: 'extra-field-app',
          sample: 'extra-field-sample'
        }    
    }));

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


In the controller in just create a Logger instance as follows and uses it:


`private readonly logger = new Logger('AppController');`

Examples:
 `this.logger.warn('English hello {lang}',{ lang: 'en' });    `

@lupu60 lupu60 self-assigned this Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants