TypeError: transport is not a constructor
alias8 opened this issue · 2 comments
alias8 commented
I tried running the code in the readme in node.js v6.2.1 and get the following error:
C:\dev\aws\winston-aws-cloudwatch-test\node_modules\winston\lib\winston\logger.js:475
var instance = created ? transport : (new (transport)(options));
^
TypeError: transport is not a constructor
at Logger.add (C:\dev\aws\winston-aws-cloudwatch-test\node_modules\winston\lib\winston\logger.js:475:41)
at Object.winston.(anonymous function) [as add] (C:\dev\aws\winston-aws-cloudwatch-test\node_modules\winston\lib\winston.js:87:34)
at Object.<anonymous> (C:\dev\aws\winston-aws-cloudwatch-test\winston-aws-cloudwatch.js:25:9)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
Here is the code that produced the error:
const config = require('./config.json')
const winston = require('winston')
const CloudWatchTransport = require('winston-aws-cloudwatch')
var options = {
logGroupName: config.cloudWatchLogGroup,
logStreamName: config.cloudWatchStream,
createLogGroup: true,
createLogStream: true,
awsConfig: {
accessKeyId: config.aws_access_key_id,
secretAccessKey: config.aws_secret_access_key,
region: config.region
},
formatLogItem: function (item) {
return item.level + ': ' + item.message + ' ' + JSON.stringify(item.meta)
}
}
var cwt = new CloudWatchTransport(options)
cwt.on('error', function (error) {
console.error('Error logging to CloudWatch: ' + error.message)
})
winston.add(cwt)
winston.info("test message");Does anyone know what this error means? Cheers
timdp commented
Hmm. The example in the readme might not be correct. It looks like add() expects a class rather than an instance. Can you try this:
winston.add(CloudWatchTransport, options)
Alternatively, you can pass an array of transports when you create your logger instance. That's what I usually do, which explains why this never happened in my own code.
Let me know if it works. I'll update the readme. Thanks for reporting!
timdp commented
I've simplified the readme in response to this issue so I'm going to close it. Let me know if you encounter any more problems.