2016-04-26 40 views
1

有没有一种方法可以格式化日志输出以在casper.log中包含时间戳?如何格式化casper.log输出?

例如:

casper.log("some debug message", "debug"); 

标准输出:[调试] [幻象] [2016-04-26T10:00:00.000]一些调试消息

回答

3

卡斯帕具有logFormats对象,它是目前not documented

由于我讨厌使用非文件化的功能,我会建议你重载日志方法来做这样的事情。

var _oldLog = casper.log; 
casper.log = function(message, level, space) { 
    var message_with_date = "[" + new Date() + "] " + message; 
    _oldLog.call(this, message_with_date, level, space); 
};