How do I set a peer dependency optional?

Since NPM v7.x, you can use the peerDependenciesMeta package.json config, which allows exactly that option. For example, in your “Module A” package.json: “peerDependencies”: { “winston”: “> 1.0.0 <= 1.2.10”, “foo”: “~2.3.0” }, “peerDependenciesMeta”: { “winston”: { “optional”: true } } In this case, when installing Module A as a dependency of another project, it will … Read more

How to set log level in Winston/Node.js

If you are using the default logger, you can adjust the log levels like this: const winston = require(‘winston’); // … winston.level=”debug”; will set the log level to ‘debug’. (Tested with winston 0.7.3, default logger is still around in 3.2.1). However, the documentation recommends creating a new logger with the appropriate log levels and then … Read more

Winston logging object

You are trying to insert a JSON object directly into the string, so it will print [Object Object] without the JSON.stringify. This is not fixable by configuring Winston, as this problem happens while the string is generated (before the logger.debug function actually reads it), so a console.log call would print the same thing. The first … Read more

How do I change my node winston JSON output to be single line

winston 3.x (current version) Default formatter const winston = require(‘winston’); const logger = winston.createLogger({ format: winston.format.json(), transports: [ new winston.transports.Console() ] }); Example const test = { t: ‘test’, array: [1, 2, 3] }; logger.info(‘your message’, test); // logger output: // {“t”:”test”,”array”:[1,2,3],”level”:”info”,”message”:”your message”} Custom formatter const winston = require(‘winston’); const { splat, combine, timestamp, printf … Read more

Winston not displaying error details

I think what you’re missing is format.errors({ stack: true }) in winston.createLogger. const logger = winston.createLogger({ level: ‘debug’, format: format.combine( format.errors({ stack: true }), print, ), transports: [new transports.Console()], }); See this GitHub thread for more information. The reason this is happening is because the interesting Error object properties, like .stack, are non-enumerable. Some functions … Read more

Winston doesn’t pretty-print to console

I figured out the answer (the documentation is incorrect). If you use the constructor, and manually add transports, you can set options, both for winston, and for individual transports. Certain options need to be added to winston directly, while others need to be added to the transport. E.g.: var winston = require(‘winston’); var logger = … Read more

How would a human read a json winston log file?

Simply set the file transport “json” property to false, and you’ll get a human readable log. Same as you see in the console. var winston = require(‘winston’); var logger = new winston.Logger({ transports: [ new winston.transports.File({ json: false, filename:’log.log’ }), new winston.transports.Console() ], exitOnError: false }); logger.log(‘info’, ‘some msg’);