Cannot create property 'Symbol(level) for logger.log (sample from Readme)
See original GitHub issueI’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 ininfo: 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:
- Created 6 years ago
- Reactions:2
- Comments:5
Top 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 >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
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 towinstonlogger
logging. We forget the first argument to the call.Ok, the problem is that there is no
log()
, should bedebug()
or something else. I guess that reason is that I switched from console to winston.It was
console.log()
, just replaceconsole
tologger
will trigger this error.