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

Nothing happens... #41

Open
demian85 opened this issue Jun 21, 2021 · 7 comments
Open

Nothing happens... #41

demian85 opened this issue Jun 21, 2021 · 7 comments

Comments

@demian85
Copy link

import pino from 'pino'
import cloudwatchStream from 'pino-cloudwatch'

const {
  CLOUDWATCH_NODEJS_LOG_GROUP,
  AWS_ACCESS_KEY_ID,
  AWS_SECRET_ACCESS_KEY,
  AWS_REGION,
} = process.env

export const logger = pino(
  {
    name: 'mqtt-broker',
    level: process.env.LOG_LEVEL || 'info',
  },
  cloudwatchStream({
    group: CLOUDWATCH_NODEJS_LOG_GROUP,
    aws_access_key_id: AWS_ACCESS_KEY_ID,
    aws_secret_access_key: AWS_SECRET_ACCESS_KEY,
    aws_region: AWS_REGION,
  })
)

in another file...

import { logger } from '../lib/logger'

logger.info(`Connecting...`, { hello: 'world' })

Nothing gets logged, no error, no nothing. What is happening? How can I debug this thing?

Thanks.

@demian85
Copy link
Author

Hello? I finally used this module to capture stdout from my script, but I was hoping to use this programmatically.
Anyway, I found another issue and I will report it.

@demian85
Copy link
Author

I guess this project is dead...

@jwalton
Copy link

jwalton commented Nov 3, 2021

I ran into the same problem and was about to throw my hands up in frustration and jump to Winston, but I poked around with a debugger and figured this out. In case anyone else ends up here...

The problem is that pino-cloudwatch will buffer logs and only send them to cloudwatch when one of the following three conditions is met:

If you don't specify an interval, or specify interval: 0, that last condition will never be satisfied! So for an app that logs infrequently, you must specify an interval.

  cloudwatchStream({
    group: CLOUDWATCH_NODEJS_LOG_GROUP,
    aws_access_key_id: AWS_ACCESS_KEY_ID,
    aws_secret_access_key: AWS_SECRET_ACCESS_KEY,
    aws_region: AWS_REGION,
    interval: 1000, // This is required.
  })

Note that this will make it so every time you send a log to pino-cloudwatch, it will wait 1000ms before sending. If you log another message in that interval, the timer will reset. If you log something every 900ms, your logs will not get sent until you reach one of the other conditions - you could be waiting a couple of hours. As this package is currently written, there's no fix for this - there's no option to specify a "maximum interval between sends".

@AlexZeitler
Copy link

I guess this project is dead...

I've created a fork to fix some issues and eventually port it to TypeScript:

https://www.npmjs.com/package/pino-aws-cloudwatch

Looking forward to PRs.

@slim-hmidi
Copy link

@jwalton I tried your solution but it does not work:

const stream = PinoCloudWatch({
    group: 'test',
    aws_access_key_id: process.env.AWS_ACCESS_KEY_ID,
    aws_secret_access_key: process.env.AWS_SECRET_ACCESS_KEY,
    interval: 1000,
    aws_region: 'eu-central-1'
  });
const logger = pino(
    {
      level: 'debug',
      serializers: pino.stdSerializers,
    },
    stream,
  );

I'm using pino v8.11.0.

@demian85
Copy link
Author

I made a package myself using streams and works great. I'll try to publish it once I have some free time.

@slim-hmidi
Copy link

@demian85 can you share the config you did to make the connection with cloudWatch please?

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

4 participants