pino-cloudwatch
pino-cloudwatch copied to clipboard
Nothing happens...
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.
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.
I guess this project is dead...
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:
- The total size of buffered logs is 262144 bytes
- The total number of buffered logs is 10K entries
- It has been at least
options.interval
milliseconds since logs were last sent (via options passed tochunky-stream
).
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".
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.
@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.
I made a package myself using streams and works great. I'll try to publish it once I have some free time.
@demian85 can you share the config you did to make the connection with cloudWatch please?