lazywithclass / winston-cloudwatch

Send logs to Amazon Cloudwatch using Winston.
MIT License
258 stars 104 forks source link

Does not work with Lambda #228

Open adamleemiller opened 5 months ago

adamleemiller commented 5 months ago

I am looking for a way to send my Winston generated logs to CloudWatch and found this module / plugin / project and had high hopes but after about two hours, I am not able to get it to work with Lambda. The code does work locally and the log stream does get created and logged to however when deploying via Lambda, the log stream is not created.

Here is the current code I am using:

const cloudwatchLogger = logger.add(new WinstonCloudWatch({
  awsOptions: {
    credentials: {
      accessKeyId: process.env.AWS_ACCESSKEYID,
      secretAccessKey: process.env.AWS_SECRETACCESSKEYID
    },
    region: process.env.CLOUDWATCH_REGION
  },
  name: 'cloudwatchLogger',
  logGroupName: process.env.CLOUDWATCH_GROUP_NAME,
  logStreamName: `${process.env.CLOUDWATCH_GROUP_NAME}-${process.env.NODE_ENV}`,
  awsRegion: process.env.CLOUDWATCH_REGION
}))

cloudwatchLogger.transports.find((t) => t.name === 'cloudwatchLogger').kthxbye(() => {
  console.log('---===...transport buffer flushed...===---')
})

It would also be great to be able to define the log formatter using the built-in Winston combine method. For example, this is what I use in my other transports:

      format: winston.format.combine(
        winston.format.errors({ stack: false }),
        winston.format.timestamp({
          format: 'MMM-DD-YYYY HH:mm:ss'
        }),
        winston.format.metadata(),
        winston.format.prettyPrint(),
        winston.format.json()
      )

Lastly, it does not appear that this project is maintained anymore. There are multiple open issues, some with fixes, but no response from the project maintainer. Is this project still supported?

lazywithclass commented 4 months ago

Hi @adamleemiller, I am not actively maintaining the project anymore.

winston-cloudwatch definitely supported AWS Lambda in the past as I wrote a function specifically for it.