Console transport does not log to AWS Lambda output
See original GitHub issuePlease tell us about your environment:
winston
version?-
winston@2
-
winston@3
-
node -v
outputs: v8.10- Operating System? Linux (AWS Lambda)
- Language? TypeScript ^3.0.0 -> webpack -> ES5
What is the problem?
Deploying a NodeJS Lambda function that uses Winston Console transport for logging fails silently to deliver log commands to the Lambda output. No errors, just no logs. Winston Console transport prefers console._stdout
and console._stderr
to console.log()
and console.error()
, but Lambda does not support console._stdout
and console._stderr
.
From console.js
:
if (console._stdout) {
// Node.js maps `process.stdout` to `console._stdout`.
console._stdout.write(`${info[MESSAGE]}${this.eol}`);
} else {
// console.log adds a newline.
console.log(info[MESSAGE]);
}
The problem I see is that console._stdout
and console._stderr
exist in the Lambda runtime environment so the checks in Winston do not fall back to console.log()
, etc.
What do you expect to happen instead?
I would expect Winston’s conditional check to account for the presence of console._stdout
and console._stderr
AND either a configuration or an environment detail that allows it to skip these methods of logging in AWS Lambda environments as they are unsupported.
Other information
I’m able to work around this in my lambda functions by including this hack in my handler file:
delete console['_stdout'];
delete console['_stderr'];
I’d love to be able to keep from modifying the prototype of console
, but this works for now.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
After 1.5 days of troubleshooting, found that all I’d to do make the logs appear in aws lambda is to pass the logger level in the right character case. I was setting it to INFO instead of info and winston had no alert statements for this misconfig.
@davemkirk I managed to get this working using https://github.com/winstonjs/winston/issues/1305#issuecomment-387634897