FormidableLabs / pino-lambda

Send pino logs to cloudwatch with aws-lambda
MIT License
125 stars 13 forks source link

How to sample x% debug logs #15

Closed s1mrankaur closed 3 years ago

s1mrankaur commented 3 years ago

We are able to add co-relationIds to our requests using this module.

  1. How can it be used to sample debug logs in production?
  2. How can we enable debug logging dynamically?
carbonrobot commented 3 years ago

Hi @s1mrankaur, pino has no built in support for sampling a % of debug logs. You may be able to build your own hook or transport to do so by checking out the documentation.

If a lambda request contains the header x-correlation-trace-debug with a value of true, debug logging will be dynamically enabled for that request.

pjain11 commented 3 years ago

Is there any way to change log level based on environment variable?

carbonrobot commented 3 years ago

@pjain11 You can use any options that pino supports.

https://getpino.io/#/docs/api?id=options

// example

const logger = pino({ level: process.env.LOG_LEVEL });
pjain11 commented 3 years ago

@carbonrobot I saw the above but i'm not sure how to make it work with pino-lambda. I tried passing that option when initializing, something like below but does not work.

import Pino from 'pino-lambda'; const pinoLogger = Pino({ level: process.env.LOG_LEVEL });

pjain11 commented 3 years ago

For future readers: I'm using this in a typescript project, i was missing to install types for pino (npm i @types/pino). That fixes the issue.