thelounge/src/log.js
Jérémie Astori caa46042bf Enforce strict mode across all JS files with ESLint
Several ES6 additions are only available in strict mode. Example:
> SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Strict mode was also enabled in a few of our files already, and it is a good thing to have anyway.
2016-10-09 15:14:02 -04:00

33 lines
858 B
JavaScript

"use strict";
var colors = require("colors/safe");
var moment = require("moment");
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";
var time = moment().utcOffset(tz).format(format);
Array.prototype.unshift.call(messageArgs, colors.dim(time), type);
return messageArgs;
}
exports.error = function() {
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));
};