[winston 2.x] fails when logging with metadata (json:false)
See original GitHub issueexample code:
const winston = require('winston');
const RollingFileTransport = require('winston-daily-rotate-file');
const options = {
json: false,
timestamp: function() {
return new Date().toISOString().substring(0, 16).replace('T',' ');
}
};
const rollingFileTransportOptions = {
filename: 'test-%DATE%.log',
datePattern: 'YYYY-MM-DD',
maxFiles: 30
};
const logger = new (winston.Logger)({
level: 'info',
transports: [
new winston.transports.Console(options),
new RollingFileTransport(Object.assign({}, rollingFileTransportOptions, options))
]
});
// works
logger.info('test');
// fails with exception
logger.info('test', {myIntField:1});
error:
output += ' ' + exports.serialize(meta);
^
TypeError: exports.serialize is not a function
at Object.exports.log (<XXXX>\node_modules\winston-compat\index.js:205:33)
at DailyRotateFile.log (<XXXX>\node_modules\winston-daily-rotate-file\daily-rotate-file.js:109:29)
at transportLog (<XXXX>\node_modules\winston\lib\winston\logger.js:234:15)
at <XXXX>\node_modules\async\lib\async.js:157:13
at _each (<XXXX>\node_modules\async\lib\async.js:57:9)
at Object.async.each (<XXXX>\node_modules\async\lib\async.js:156:9)
at Logger.log (<XXXX>\node_modules\winston\lib\winston\logger.js:246:9)
at target.(anonymous function) [as info] (<XXXX>\node_modules\winston\lib\winston\common.js:54:18)
at Object.<anonymous> (<XXXX>\log.js:28:8)
at Module._compile (module.js:570:32)
if I install the winston-compat dependency from github it works correctly (it seems their latest commit 0a6c478 fixed this issue). However, the latest version published on npm (0.0.1) is behind.
A possible fix is to update package.json to use instead:
"winston-compat": "git+https://github.com/winstonjs/winston-compat.git#0a6c478"
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
nodejs winston - Logging with multiple arguments
1. logger.info("We got the data %s, %d", data, port); O/P: We got the data %s, %d => No data and port value 2....
Read more >A Complete Guide to Winston Logging in Node.js - Better Stack
Utilizing and customizing Winston log levels. Various ways to format your log entries. How to add context or metadata to your log entries....
Read more >Node Logging Basics - The Ultimate Guide To Logging - Loggly
Popular Libraries. There are many third-party logging libraries available for Node.js. In this guide, we're going to look at primarily Winston and Pino....
Read more >winston - npm.io
winston is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device...
Read more >[Solved]-Multiple log files with Winston?-node.js - appsloveworld
File({ filename: 'error.log', level: 'error' }), new winston.transports. ... filename: logFile, json: false }), new (winston.transports.
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
New version of
winston-compat
published to npm. Updated this project to referencewinston-compat@0.1.0
and published to npm. Should be resolved withnpm install winston-daily-rotate-file@3.0.1
.@lpfeup’s workaround works fine for me. But, Its better if the fix is released on npm.