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.

[winston 2.x] fails when logging with metadata (json:false)

See original GitHub issue

example 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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mattberthercommented, Mar 23, 2018

New version of winston-compat published to npm. Updated this project to reference winston-compat@0.1.0 and published to npm. Should be resolved with npm install winston-daily-rotate-file@3.0.1.

0reactions
shravan-shandilyacommented, Mar 22, 2018

@lpfeup’s workaround works fine for me. But, Its better if the fix is released on npm.

Read more comments on GitHub >

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

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