thelounge/src/log.js

46 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
2016-04-16 13:32:38 +02:00
var colors = require("colors/safe");
var moment = require("moment");
const read = require("read");
2016-04-16 13:32:38 +02:00
var Helper = require("./helper");
function timestamp(type, messageArgs) {
var format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
var tz = Helper.config.logs.timezone || "UTC+00:00";
2016-04-16 13:32:38 +02:00
var time = moment().utcOffset(tz).format(format);
Array.prototype.unshift.call(messageArgs, colors.dim(time), type);
return messageArgs;
}
/* eslint-disable no-console */
exports.error = function() {
2016-04-16 13:32:38 +02:00
console.error.apply(console, timestamp(colors.red("[ERROR]"), arguments));
};
exports.warn = function() {
console.error.apply(console, timestamp(colors.yellow("[WARN]"), arguments));
};
exports.info = function() {
console.log.apply(console, timestamp(colors.blue("[INFO]"), arguments));
};
exports.debug = function() {
console.log.apply(console, timestamp(colors.green("[DEBUG]"), arguments));
};
exports.raw = function() {
console.log.apply(console, arguments);
};
/* eslint-enable no-console */
exports.prompt = (options, callback) => {
options.prompt = timestamp(colors.cyan("[PROMPT]"), [options.text]).join(" ");
read(options, callback);
};