[3.0.0] Error object is not parsed or printed
See original GitHub issuePlease tell us about your environment:
winston
version?- [-]
winston@3.0.0-rc5
- [-]
node -v
outputs: v8.11.1- Operating System? (Windows, macOS, or Linux) macOS
- Language? (all | TypeScript X.X | ES6/7 | ES5 | Dart) All
What is the problem?
Logging a node Error
object results in an empty message:
Example:
const winston = require('winston');
const { createLogger, format, transports } = winston;
const logger = createLogger({
transports: [
new transports.Console()
]
});
let err = new Error('this is a test');
logger.log({level: 'error', message: err});
Resulting output:
% node test.js
{"level":"error","message":{}}
Also:
logger.error(new Error('hello'))
Results in:
{"level":"error"}
What do you expect to happen instead?
I Expect the message key to have at least the error message included in it. If I try a custom formatter, info
also doesn’t have the error object in it so it must be stripped out somewhere?
Other information
Let me know how I can help - happy to flick a PR but I don’t know my way around winston@3.0.0
enough yet to find it
Issue Analytics
- State:
- Created 5 years ago
- Reactions:89
- Comments:73 (8 by maintainers)
Top Results From Across the Web
Can print out an object, but cannot access its values in JS
The problem is that data is a JSON string so you can't access it before parsing it, that's why data.nf_ingredient_statement is undefined ....
Read more >json-parse-even-better-errors | Yarn - Package Manager
It also preserves the newline and indentation styles of the JSON data, by putting them in the object or array in the Symbol.for('indent')...
Read more >Module: JSON (Ruby 3.0.0)
When the source is a JSON scalar (not an array or object), JSON.parse returns a Ruby ... Raises TypeError (wrong argument type Symbol...
Read more >csv-parser - npm
Some CSV files may be generated with, or contain a leading Byte Order Mark. This may cause issues parsing headers and/or data from...
Read more >Changelog - Cypress Documentation
While it's not strictly necessary for Cypress to parse your configuration, we recommend wrapping your config object with defineConfig() .
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
No really, this is unacceptable for a logging library. Maintainer should simply put a well highlighted example on docs where it is shown how to log an error, even defining custom printf format and non json format and where you can log error with something like logger.error(“something”, err) and logger.error(err) Winston seemed to be great but this issue is incredibly unacceptable
Am I missing something, or is it a complete headache (or even impossible?) to get the same output one easily gets from console.log/error/warn?
What is the equivalent winston code to get the same output as
console.error('Caught error:', error);
?And where is the documentation for the parameters taken by the convenience methods on the logger object?