Use Date.toISOString for logging

This commit is contained in:
Pavel Djundik 2018-09-20 14:15:05 +03:00
parent 3b9b5e26f4
commit 88ce0cee99
3 changed files with 4 additions and 13 deletions

View file

@ -2,10 +2,11 @@
const colors = require("chalk"); const colors = require("chalk");
const read = require("read"); const read = require("read");
const moment = require("moment");
function timestamp() { function timestamp() {
return colors.dim(module.exports.getHumanDate()); const datetime = (new Date()).toISOString().split(".")[0].replace("T", " ");
return colors.dim(datetime);
} }
module.exports = { module.exports = {
@ -31,8 +32,4 @@ module.exports = {
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" "); options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
read(options, callback); read(options, callback);
}, },
getHumanDate(ts) {
return moment(ts).format("YYYY-MM-DD HH:mm:ss");
},
}; };

View file

@ -40,7 +40,7 @@ class TextFileMessageStorage {
return; return;
} }
let line = `[${log.getHumanDate(msg.time)}] `; let line = `[${msg.time.toISOString()}] `;
// message types from src/models/msg.js // message types from src/models/msg.js
switch (msg.type) { switch (msg.type) {

View file

@ -2,9 +2,7 @@
const expect = require("chai").expect; const expect = require("chai").expect;
const os = require("os"); const os = require("os");
const moment = require("moment");
const Helper = require("../../src/helper"); const Helper = require("../../src/helper");
const log = require("../../src/log");
describe("Helper", function() { describe("Helper", function() {
describe("#expandHome", function() { describe("#expandHome", function() {
@ -54,8 +52,4 @@ describe("Helper", function() {
expect(version).to.match(/v[0-9]+\.[0-9]+\.[0-9]+/); expect(version).to.match(/v[0-9]+\.[0-9]+\.[0-9]+/);
}); });
}); });
describe("#getHumanDate()", function() {
expect(log.getHumanDate(moment(1455090480000).utc())).to.equal("2016-02-10 07:48:00");
});
}); });