mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
/* Magic Mirror
|
|
* Logger
|
|
* 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.
|
|
*
|
|
* By Michael Teeuw https://michaelteeuw.nl
|
|
* MIT Licensed.
|
|
*/
|
|
(function (root, factory) {
|
|
if (typeof exports === "object") {
|
|
// add timestamps in front of log messages
|
|
require("console-stamp")(console, "yyyy-mm-dd HH:MM:ss.l");
|
|
|
|
// Node, CommonJS-like
|
|
module.exports = factory(root.config);
|
|
} else {
|
|
// Browser globals (root is window)
|
|
root.Log = factory(root.config);
|
|
}
|
|
})(this, function (config) {
|
|
let logLevel = {
|
|
info: Function.prototype.bind.call(console.info, console),
|
|
log: Function.prototype.bind.call(console.log, console),
|
|
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)
|
|
};
|
|
|
|
if (config && config.logLevel) {
|
|
Object.keys(logLevel).forEach(function (key, index) {
|
|
if (!config.logLevel.includes(key.toLocaleUpperCase())) {
|
|
logLevel[key] = function () {};
|
|
}
|
|
});
|
|
}
|
|
|
|
return logLevel;
|
|
});
|