timdp / winston-aws-cloudwatch

A Winston transport for Amazon CloudWatch.
MIT License
47 stars 13 forks source link

**TypeError: item.level.toUpperCase() is not a function** #80

Closed Juanelorganelo closed 6 years ago

Juanelorganelo commented 6 years ago

I'm getting an error using this transport, it appears to be from the library itself Here is the stack trace

TypeError: item.level.toUpperCase is not a function
    at CloudWatchEventFormatter.formatLog (/home/user/documents/library/node_modules/winston-aws-cloudwatch/lib/cloudwatch-event-formatter.js:35:27)
    at CloudWatchEventFormatter.formatLogItem (/home/user/documents/library/node_modules/winston-aws-cloudwatch/lib/cloudwatch-event-formatter.js:28:21)
    at params.logEvents.batch.map.item (/home/user/documents/library/node_modules/winston-aws-cloudwatch/lib/cloudwatch-client.js:120:52)
    at Array.map (<anonymous>)
    at CloudWatchClient._putLogEvents (/home/user/documents/library/node_modules/winston-aws-cloudwatch/lib/cloudwatch-client.js:120:24)
    at CloudWatchClient._putLogEventsAndStoreSequenceToken (/home/user/documents/library/node_modules/winston-aws-cloudwatch/lib/cloudwatch-client.js:111:17)
    at _maybeUpdateSequenceToken.then (/home/user/documents/library/node_modules/winston-aws-cloudwatch/lib/cloudwatch-client.js:90:61)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)

here is the code

export const log = winston.createLogger({
  level: 'debug',
  format: winston.format.json(),
  transports: [
    new CloudWatchTransport({
      level: 'error',
      createLogGroup: true,
      createLogStream: true,
      logGroupName: AWS_CLOUDWATCH_GROUP,
      logStreamName: 'errors',
    }),
  ],
  awsConfig: {
    accessKeyId: AWS_ACCESS_KEY_ID,
    secretAccessKey: AWS_SECRET_ACCESS_KEY,
    region: AWS_REGION,
  },
});

log.info('bla');
timdp commented 6 years ago

Interesting. I thought log items always had a level property. Can you pass your own formatLog implementation via the options and output the raw log item that it's trying to format? Thanks!

frisibeli commented 6 years ago

I was getting the same error and I managed to fix it by applying this patch:

let cwTransport = new CloudWatchTransport(config);
Object.assign(cwTransport, {
      log:(...args) => {
            let callback = args[1];
            cwTransport._relay.submit({date:+new Date(), ...args[0], callback});
      }
})
timdp commented 6 years ago

@frisibeli Are you on Winston v3 by any chance? It looks like the transport API changed.

frisibeli commented 6 years ago

@timdp Yes, my Winston version is winston@3.0.0-rc3

timdp commented 6 years ago

That would explain it. I started implementing Winston 3 support on the winston3 branch today but it's currently untested.

bra1n commented 6 years ago

Any idea when this branch is going to be merged into master? As it is, using the branch directly with npm won't work.

timdp commented 6 years ago

Thanks for your patience. I've just published v3.0.0 which supports winston 3.