hardlounge/src/log.js

43 lines
1.0 KiB
JavaScript
Raw Normal View History

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