Search code examples
loggingcommand-line-interfacewinston

Winston logger cli method is not working


I am trying CLI mehtod on my logger instance for pretty printing , but it doesn't seem to be working.

var logger = new winston.Logger({
transports: [

     new winston.transports.File({
        level: info
        filename: 'filename',
        json: true,
        name: 'all-log-file',
        colorize: true,
        prettyPrint: true
    })
 ]
});

logger.cli();

But this is not working for me.Expected output format is like following:

 info:   Found existing dependencies
 data:   {
 data:     colors: '0.x.x',
 data:     eyes: '0.1.x',
 data:     findit: '0.0.x',
 data:     npm: '1.0.x',
 data:     optimist: '0.2.x',
 data:     semver: '1.0.x',
 data:     winston: '0.2.x'
 data:   }
 info:   Analyzing dependencies...
 info:   Done analyzing raw dependencies
 info:   Retrieved packages from npm
 warn:   No additional dependencies found

I want pretty printed, colorized output, any help?


Solution

  • Did you try console transport?

    var winston = require('winston');
    
    var logger = new winston.Logger({
        transports: [
            new winston.transports.File({
                level: 'debug',
                filename: 'prettylog.txt',
                handleExceptions: true,
                json: false,
                colorize: true,
                timestamp: true,
                prettyPrint: true
            })
        ],
        exitOnError: false
    });
    

    Now, you have to show the content using a standard Unix utility: cat prettylog.txt