【问题标题】:Winston logger cli method is not working温斯顿记录器 cli 方法不起作用
【发布时间】:2015-03-20 18:41:12
【问题描述】:

我正在我的记录器实例上尝试 CLI mehtod 以进行漂亮的打印,但它似乎不起作用。

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();

但这对我不起作用。预期的输出格式如下:

 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

我想要漂亮的彩色打印输出,有什么帮助吗?

【问题讨论】:

    标签: logging command-line-interface winston


    【解决方案1】:

    您尝试过控制台传输吗?

    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
    });
    

    现在,您必须使用标准 Unix 实用程序显示内容: cat prettylog.txt

    【讨论】:

    • 感谢 A.DIMO 的帮助。但是,我希望使其适用于文件传输。可以使用温斯顿吗?
    • 其实我用的是windows机器:(
    • 如果你已经安装了 msysgit(又名 Git for Windows),你可以使用 BASH 仿真。
    猜你喜欢
    • 2018-11-21
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    • 2017-03-23
    • 2018-07-27
    相关资源
    最近更新 更多