question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[3.0.0] Error object is not parsed or printed

See original GitHub issue

Please 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:closed
  • Created 5 years ago
  • Reactions:89
  • Comments:73 (8 by maintainers)

github_iconTop GitHub Comments

72reactions
andretti1977commented, Apr 30, 2020

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

60reactions
dandvcommented, Jul 8, 2018

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?

try {
   // ...
  throw new Error('foo');
} catch (e) {
  console.error('Caught error:', e);  // convenient, informative
  logger.error('Caught error:', e);  // nope, the second parameter is something else (couldn't find docs)
  logger.error(`Caught error: ${e}`);  // stack lost
  logger.error(`Caught error: ${JSON.stringify(e)}`);  // Caught error: {}
}

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found