2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-04-16 11:32:38 +00:00
|
|
|
var colors = require("colors/safe");
|
|
|
|
var moment = require("moment");
|
2016-12-16 07:27:41 +00:00
|
|
|
const read = require("read");
|
2016-04-16 11:32:38 +00:00
|
|
|
var Helper = require("./helper");
|
|
|
|
|
|
|
|
function timestamp(type, messageArgs) {
|
2016-06-08 09:26:24 +00:00
|
|
|
var format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
|
|
|
|
var tz = Helper.config.logs.timezone || "UTC+00:00";
|
2016-04-16 11:32:38 +00:00
|
|
|
|
|
|
|
var time = moment().utcOffset(tz).format(format);
|
|
|
|
|
|
|
|
Array.prototype.unshift.call(messageArgs, colors.dim(time), type);
|
|
|
|
|
|
|
|
return messageArgs;
|
|
|
|
}
|
|
|
|
|
2017-09-18 01:50:21 +00:00
|
|
|
/* eslint-disable no-console */
|
2016-04-27 07:42:54 +00:00
|
|
|
exports.error = function() {
|
2016-04-16 11:32:38 +00: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));
|
|
|
|
};
|
2017-12-09 07:11:05 +00:00
|
|
|
|
|
|
|
exports.raw = function() {
|
|
|
|
console.log.apply(console, arguments);
|
|
|
|
};
|
|
|
|
|
2017-09-18 01:50:21 +00:00
|
|
|
/* eslint-enable no-console */
|
2016-12-15 06:13:43 +00:00
|
|
|
|
2016-12-16 07:27:41 +00:00
|
|
|
exports.prompt = (options, callback) => {
|
|
|
|
options.prompt = timestamp(colors.cyan("[PROMPT]"), [options.text]).join(" ");
|
|
|
|
read(options, callback);
|
2016-12-15 06:13:43 +00:00
|
|
|
};
|