add timestamps to log

This commit is contained in:
Asraelite 2016-03-27 12:01:39 +01:00
parent 663305bd23
commit 0ea163dfb7
6 changed files with 43 additions and 14 deletions

28
server/interface.js Normal file
View file

@ -0,0 +1,28 @@
'use strict';
require('colors');
class ServerInterface {
constructor() {
}
log(msg) {
let pad = (str, len, right) => {
str = '' + str;
return (right ? str : '') +
Array(len > str.length ? 1 + len - str.length : 0)
.join('0') + (right ? '' : str);
}
let d = new Date();
let timestamp =
`<${pad(d.getUTCHours(), 2)}:` +
`${pad(d.getUTCMinutes(), 2)}:` +
`${pad(d.getUTCSeconds(), 2)}.` +
`${pad(('' + d.getUTCMilliseconds()).slice(0, 2), 2, true)}> `;
console.log(timestamp.gray, msg);
}
}
module.exports = ServerInterface;