hardlounge/src/log.js

39 lines
871 B
JavaScript
Raw Normal View History

"use strict";
2018-03-02 18:28:54 +00:00
const colors = require("chalk");
const read = require("read");
const moment = require("moment");
2016-04-16 11:32:38 +00:00
function timestamp() {
return colors.dim(module.exports.getHumanDate());
2016-04-16 11:32:38 +00:00
}
module.exports = {
/* eslint-disable no-console */
error(...args) {
console.error(timestamp(), colors.red("[ERROR]"), ...args);
},
warn(...args) {
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
},
info(...args) {
console.log(timestamp(), colors.blue("[INFO]"), ...args);
},
debug(...args) {
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
},
raw(...args) {
console.log(...args);
},
/* eslint-enable no-console */
prompt(options, callback) {
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
read(options, callback);
},
getHumanDate() {
return moment().format("YYYY-MM-DD HH:mm:ss");
},
};