Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winston doesn't pretty-print to console

I'm trying to get Winston to pretty print to the console, so I stuck this in a file and ran it with node:

var winston = require('winston'); winston.cli(); winston.data({   a: "test",   of: "many",   properties: {     like: "this"   } }); winston.data('data', {   a: "test",   of: "many",   properties: {     like: "this"   } }); 

The terminal spit back the following (not exactly pretty) messages:

data:     a=test, of=many, like=this data:    data a=test, of=many, like=this 

I'm following the instructions on the Winston Readme ("Using winston in a CLI tool"). Am I misreading something? Missing a setting somewhere?

like image 391
JoBu1324 Avatar asked Jul 31 '13 06:07

JoBu1324


People also ask

Does Winston use console log?

Winston allows you to implement multiple logging transports, i.e., a log can be recorded to a file, console, or database. The Logger configuration below logs to a console and a file.

Is Winston asynchronous?

After a quick review of the source on github, I'd say that no, winston is not truly async in all aspects. It does emit , but EventEmitter is not async. Methods have an async-style signature (w/ callback ), but are not always async.


1 Answers

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 = new (winston.Logger)({   levels: {     trace: 0,     input: 1,     verbose: 2,     prompt: 3,     debug: 4,     info: 5,     data: 6,     help: 7,     warn: 8,     error: 9   },   colors: {     trace: 'magenta',     input: 'grey',     verbose: 'cyan',     prompt: 'grey',     debug: 'blue',     info: 'green',     data: 'grey',     help: 'cyan',     warn: 'yellow',     error: 'red'   } });  logger.add(winston.transports.Console, {   level: 'trace',   prettyPrint: true,   colorize: true,   silent: false,   timestamp: false });  logger.add(winston.transports.File, {   prettyPrint: false,   level: 'info',   silent: false,   colorize: true,   timestamp: true,   filename: './nKindler.log',   maxsize: 40000,   maxFiles: 10,   json: false }); 
like image 198
JoBu1324 Avatar answered Sep 23 '22 06:09

JoBu1324