winston-cloudwatch icon indicating copy to clipboard operation
winston-cloudwatch copied to clipboard

Browser Cloud Watch Support

Open drmmr763 opened this issue 7 years ago • 2 comments
trafficstars

Hi All

I was really excited to use this in my project which is based on create-react-app. After installing and including in my error handler I realized that this module seems to be pretty squarely designed for server-side nodejs projects.

I got all sorts of errors like this: Can't resolve 'dns' in '/home/app/frontend/node_modules/pac-resolver which clued me into the fact this doesn't seem to be working for client side javascript or create-react-app projects.

It looks like Winston was also not really designed for browser support originally either but recently in V3 they made this possible (https://github.com/winstonjs/winston/issues/287). I've had success making it work with the Console driver. My plan was to use this CloudWatch driver for production.

If anyone knows how to make this work with a client side JS app or if there's plans to make it compatible for that platform, that would be great to hear or find out about.

Chad

drmmr763 avatar Sep 13 '18 17:09 drmmr763

Hi @drmmr763, I don't have plans to support client side at the moment. I am open to suggestions or PRs though.

lazywithclass avatar Sep 24 '18 13:09 lazywithclass

If anyone is looking for this, I came across this issue and was the first result on Google so I tough better share what I have done.

In order to get it work I simply used a custom instance of CloudWatchLogs as following:

winston.add(new WinstonCloudWatch({
        cloudWatchLogs: new AWS.CloudWatchLogs({
          region: AwsConfig.Logging.awsRegion, 
          credentials: {
            accessKeyId: "something from a secure location",
            secretAccessKey: "something from a secure location"
          }
        }),
        ...AwsConfig.Logging
      }));

In my case I also created a very strict policy so that FE can only add logs no more, what to do there really depends on your use-case.

In terms of modules version:

  • winston: 3.7.2
  • winston-cloudwatch: 6.0.1
  • @aws-sdk/client-cloudwatch-logs: 3.100.0

quirinobrizi avatar Jul 08 '22 08:07 quirinobrizi