Because I despise nitpicking stuff like indentation and spacing in pull request comments, I'd like to nudge forward our automated style checking, at least for new files being added. I don't want to totally rewrite server.js just to get automated style checking… the blame tracking is just too useful. So let's it's just take care of that when we start splitting it out. More discussion in #948.
28 lines
639 B
JavaScript
28 lines
639 B
JavaScript
'use strict';
|
|
|
|
// Zero-pad a number in a string.
|
|
// eg. 4 becomes 04 but 17 stays 17.
|
|
function pad(string) {
|
|
string = String(string);
|
|
return (string.length < 2) ? ('0' + string) : string;
|
|
}
|
|
|
|
// Compact date representation.
|
|
// eg. 0611093840 for June 11, 9:38:40 UTC.
|
|
function date() {
|
|
const date = new Date();
|
|
return pad(date.getUTCMonth() + 1) +
|
|
pad(date.getUTCDate()) +
|
|
pad(date.getUTCHours()) +
|
|
pad(date.getUTCMinutes()) +
|
|
pad(date.getUTCSeconds());
|
|
}
|
|
|
|
module.exports = function log(...msg) {
|
|
console.log(date(), ...msg);
|
|
};
|
|
|
|
module.exports.error = function error(...msg) {
|
|
console.error(date(), ...msg);
|
|
};
|