2016-03-24 17:19:32 +01:00
|
|
|
/* Magic Mirror
|
2020-06-01 16:40:20 +02:00
|
|
|
* Log
|
|
|
|
*
|
2020-05-03 18:59:26 +02:00
|
|
|
* This logger is very simple, but needs to be extended.
|
|
|
|
* This system can eventually be used to push the log messages to an external target.
|
2016-03-24 17:19:32 +01:00
|
|
|
*
|
2020-04-28 23:05:28 +02:00
|
|
|
* By Michael Teeuw https://michaelteeuw.nl
|
2016-03-24 17:19:32 +01:00
|
|
|
* MIT Licensed.
|
|
|
|
*/
|
2020-05-11 07:22:40 +02:00
|
|
|
(function (root, factory) {
|
2020-05-25 18:57:15 +02:00
|
|
|
if (typeof exports === "object") {
|
2020-05-11 07:23:21 +02:00
|
|
|
// add timestamps in front of log messages
|
|
|
|
require("console-stamp")(console, "yyyy-mm-dd HH:MM:ss.l");
|
|
|
|
|
2020-05-11 07:22:40 +02:00
|
|
|
// Node, CommonJS-like
|
|
|
|
module.exports = factory(root.config);
|
|
|
|
} else {
|
|
|
|
// Browser globals (root is window)
|
|
|
|
root.Log = factory(root.config);
|
|
|
|
}
|
2020-05-25 18:57:15 +02:00
|
|
|
})(this, function (config) {
|
2020-07-10 23:03:36 +02:00
|
|
|
const logLevel = {
|
2016-11-14 00:00:12 -03:00
|
|
|
info: Function.prototype.bind.call(console.info, console),
|
2020-05-11 22:22:32 +02:00
|
|
|
log: Function.prototype.bind.call(console.log, console),
|
2016-11-14 00:00:12 -03:00
|
|
|
error: Function.prototype.bind.call(console.error, console),
|
|
|
|
warn: Function.prototype.bind.call(console.warn, console),
|
|
|
|
group: Function.prototype.bind.call(console.group, console),
|
|
|
|
groupCollapsed: Function.prototype.bind.call(console.groupCollapsed, console),
|
|
|
|
groupEnd: Function.prototype.bind.call(console.groupEnd, console),
|
|
|
|
time: Function.prototype.bind.call(console.time, console),
|
|
|
|
timeEnd: Function.prototype.bind.call(console.timeEnd, console),
|
|
|
|
timeStamp: Function.prototype.bind.call(console.timeStamp, console)
|
2020-05-25 18:57:15 +02:00
|
|
|
};
|
2020-05-11 07:46:56 +02:00
|
|
|
|
2020-07-04 22:02:39 +02:00
|
|
|
logLevel.setLogLevel = function (newLevel) {
|
|
|
|
if (newLevel) {
|
|
|
|
Object.keys(logLevel).forEach(function (key, index) {
|
|
|
|
if (!newLevel.includes(key.toLocaleUpperCase())) {
|
|
|
|
logLevel[key] = function () {};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2020-05-11 07:46:56 +02:00
|
|
|
|
|
|
|
return logLevel;
|
2020-05-25 18:57:15 +02:00
|
|
|
});
|