2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const colors = require("colors/safe");
|
|
|
|
const moment = require("moment");
|
2016-12-16 07:27:41 +00:00
|
|
|
const read = require("read");
|
2018-01-11 11:33:36 +00:00
|
|
|
const Helper = require("./helper");
|
2016-04-16 11:32:38 +00:00
|
|
|
|
2017-11-22 06:39:32 +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
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
return colors.dim(time);
|
2016-04-16 11:32:38 +00:00
|
|
|
}
|
|
|
|
|
2017-09-18 01:50:21 +00:00
|
|
|
/* eslint-disable no-console */
|
2017-11-22 06:39:32 +00:00
|
|
|
exports.error = function(...args) {
|
|
|
|
console.error(timestamp(), colors.red("[ERROR]"), ...args);
|
2016-04-16 11:32:38 +00:00
|
|
|
};
|
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
exports.warn = function(...args) {
|
|
|
|
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
|
2016-04-16 11:32:38 +00:00
|
|
|
};
|
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
exports.info = function(...args) {
|
|
|
|
console.log(timestamp(), colors.blue("[INFO]"), ...args);
|
2016-04-16 11:32:38 +00:00
|
|
|
};
|
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
exports.debug = function(...args) {
|
|
|
|
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
|
2016-04-16 11:32:38 +00:00
|
|
|
};
|
2017-12-09 07:11:05 +00:00
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
exports.raw = function(...args) {
|
|
|
|
console.log(...args);
|
2017-12-09 07:11:05 +00:00
|
|
|
};
|
|
|
|
|
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) => {
|
2017-11-22 06:39:32 +00:00
|
|
|
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
|
2016-12-16 07:27:41 +00:00
|
|
|
read(options, callback);
|
2016-12-15 06:13:43 +00:00
|
|
|
};
|