我试图使用console-stamp登录node.js,如下所示:
require('console-stamp')(console, {
datePrefix:'',
dateSuffix: '',
pattern: 'dd/mm/yyyy HH:MM:ss.l'
});
var log = {
info: function (info) {
console.info(info);
},
warning:function (warning) {
console.warn(warning);
},
error:function (error) {
console.error(error);
},
debug:function (debug) {
console.log(debug);
}
};
module.exports = log
但是,我看到的是,在日志中,毫秒值跨越了第二个边界,如下所示:
24/10/2018 12:21:40.673 [LOG] log
24/10/2018 12:21:40.675 [LOG] log
24/10/2018 12:21:45.680 [LOG] log
24/10/2018 12:21:45.688 [LOG] log
24/10/2018 12:21:50.692 [LOG] log
24/10/2018 12:21:50.694 [LOG] log
24/10/2018 12:21:55.699 [LOG] log
24/10/2018 12:21:55.702 [LOG] log
24/10/2018 12:22:00.706 [LOG] log
24/10/2018 12:22:00.707 [LOG] log
24/10/2018 12:22:05.711 [LOG] log
24/10/2018 12:22:05.715 [LOG] log
然后,“毫秒”值将达到999,并从0重新启动。
根据链接到https://github.com/starak/node-console-stamp的http://blog.stevenlevithan.com/archives/date-time-format,"l“是毫秒的正确格式。我还尝试使用"L“,甚至手动打印新日期的getMilliseconds(),如下所示:
debug: function (debug) {
var currentTime = new Date();
var ms = currentTime.getMilliseconds();
console.log(ms + " !!!! " + debug);
}
我仍然得到一个在日志中增长的值。
有人见过这种事吗?你知道如何得到一个合理的毫秒值吗?
发布于 2018-10-24 15:50:42
您正在以模式打印您的消息,可能会使用您在注释中提到的setInterval
。
您首先打印2条连续日志消息,然后等待5秒钟,然后打印2条新消息。因此,毫秒将以升序模式显示。打印第一条消息后,执行下一个函数需要2毫秒,所以下一个时间戳将是milliseconds+2
,然后等待5秒,再等待5毫秒执行时间(这可能略有变化),因此下一个时间戳是milliseconds + 2 + 5000 + 5
....and,等等。
库或代码没有任何问题。
https://stackoverflow.com/questions/52969190
复制相似问题