add timestamps to log
This commit is contained in:
parent
663305bd23
commit
0ea163dfb7
6 changed files with 43 additions and 14 deletions
28
server/interface.js
Normal file
28
server/interface.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue