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.

Cannot create property 'Symbol(level) for logger.log (sample from Readme)

See original GitHub issue

I’ve set up a logger from the example given in README.md:


import winston from 'winston';

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    // - Write to all logs with level `info` and below to `combined.log`
    // - Write all logs error (and below) to `error.log`.
    //
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' })
  ]
});

// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
if (process.env.NODE_ENV !== 'production') {
  logger.add(
    new winston.transports.Console({
      format: winston.format.simple()
    })
  );
}

export default logger;

I’ve got some trouble with it:

  • logger.info() appends an empty {} to simple strings:

    logger.info(`Server listening on port ${config('port')}`) will result in

    info: Server listening on port 3000 {}

  • logger.log() doesn’t exist at all, it seems:

    level[LEVEL] = level.level; ^ TypeError: Cannot create property ‘Symbol(level)’ on string ‘Server listening on port 3000’

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

33reactions
roschlercommented, Oct 24, 2018

Leaving this here for others who come to this thread. The winstonlogger object does have a .log() method. However, unlike console.log(), it requires two arguments, not just one. If you forget the first argument, the log message category, you will get the Symbol(level) error.

For example, this gets the error:

winstonlogger.log('The transaction failed.');

This does not:

winstonlogger.log('error', 'The transaction failed.');

This is why this happens to many of us when we convert from console logging to winstonlogger logging. We forget the first argument to the call.

22reactions
thomasyuancommented, Apr 17, 2018

Ok, the problem is that there is no log(), should be debug() or something else. I guess that reason is that I switched from console to winston.
It was console.log(), just replace console to logger will trigger this error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot create property 'Symbol(level) for logger.log (sample ...
I've set up a logger from the example given in README.md: import winston from 'winston'; const logger = winston.createLogger({ level: 'info' ...
Read more >
how to pass a object inside the logger.log() file in winston ...
{ TypeError: Cannot create property 'Symbol(level)' on string 'Registering Device typeac' at DerivedLogger.log ...
Read more >
Cannot create property 'Symbol(level)' on string 'image
I am using Windows Server 2016 Node version v10.15.1 The issue i am experiencing is: Cannot create property 'Symbol(level)' on...
Read more >
Cannot create property 'Symbol(level) for logger.log - velog
log () method. However, unlike console.log(), it requires two arguments, not just one. If you forget the first argument, the log message category ......
Read more >
winston - npm
Each winston logger can have multiple transports (see: Transports) configured at different levels (see: Logging levels). For example ...
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