Can not log variables that are `null` or `undefined`
See original GitHub issueHello! I’m having an issue with logging variables if I expect them to sometimes be null
or undefined
.
I am using a custom formatter, but disabling this does not fix the problem.
Error when console.log()
-ing the error:
TypeError: Cannot read property 'message' of undefined
at DerivedLogger.(anonymous function) [as debug] (<...>\node_modules\winston\lib\winston\create-logger.js:43:26)
And from my logger logging its own error,:
15:52:25 error: Cannot read property 'message' of undefined
Steps to reproduce
- Call a winston logger with an undefined variable or object, e.g.
logger.debug(null);
orlet myVar = undefined; logger.info(myVar);
.
Expected behaviour
- Winston logs the error according to all the formats applied to it.
- Execution continues.
Actual behaviour
- Winston logs a
Cannot read property 'message' of null/undefined
error. - Execution halts.
System info
- Windows 10
- NodeJS v. 8.9.1
- npm v. 5.6.0
- winston v. 3.0.0-rc1
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
JavaScript: Check if Variable is undefined or null - Stack Abuse
In this short guide, you'll learn how to check if a variable is undefined, null or nil in vanilla JavaScript and with Lodash...
Read more >How can I determine if a variable is 'undefined' or 'null'?
This should work for any variable that is either undeclared or declared and explicitly set to null or undefined. The boolean expression should...
Read more >How to Determine If Variable is Undefined or NULL in JavaScript
Answer: Use the equality operator ( == ). In JavaScript if a variable has been declared, but has not been assigned a value,...
Read more >Check if Variable is NULL or Undefined in JavaScript
Use the logical OR (||) operator to check if a variable is null or undefined . The if block will only run if...
Read more >How to Check if the Variable is undefined or null in Javascript
In JavaScript, undefined and null are both falsy values, which indicate no value or absence of values within a variable. Users can check...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, does this also happen with the latest rc (
3.0.0-rc5
)? If so, any chance you can show us how your logger and transports are setup/defined?Wow, I’m really nailing it with the searches! Thanks for clearing that up, and thanks for the help. If I think of some way to handle it, I’ll be sure to comment.