mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
In the latest versions of ESLint, more and more formatting rules were removed or declared deprecated. These rules have been integrated into the new Stylistic package (https://eslint.style/guide/why) and expanded. Stylistic acts as a better formatter for JavaScript as Prettier. With this PR there are many changes that make the code more uniform, but it may be difficult to review due to the large amount. Even if I have no worries about the changes, perhaps this would be something for the release after next. Let me know what you think.
80 lines
2.2 KiB
JavaScript
80 lines
2.2 KiB
JavaScript
/* MagicMirror²
|
|
* Log
|
|
*
|
|
* 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") {
|
|
if (process.env.JEST_WORKER_ID === undefined) {
|
|
// add timestamps in front of log messages
|
|
require("console-stamp")(console, {
|
|
pattern: "yyyy-mm-dd HH:MM:ss.l",
|
|
include: ["debug", "log", "info", "warn", "error"]
|
|
});
|
|
}
|
|
// Node, CommonJS-like
|
|
module.exports = factory(root.config);
|
|
} else {
|
|
// Browser globals (root is window)
|
|
root.Log = factory(root.config);
|
|
}
|
|
}(this, function (config) {
|
|
let logLevel;
|
|
let enableLog;
|
|
if (typeof exports === "object") {
|
|
// in nodejs and not running with jest
|
|
enableLog = process.env.JEST_WORKER_ID === undefined;
|
|
} else {
|
|
// in browser and not running with jsdom
|
|
enableLog = typeof window === "object" && window.name !== "jsdom";
|
|
}
|
|
|
|
if (enableLog) {
|
|
logLevel = {
|
|
debug: Function.prototype.bind.call(console.debug, console),
|
|
log: Function.prototype.bind.call(console.log, console),
|
|
info: Function.prototype.bind.call(console.info, console),
|
|
warn: Function.prototype.bind.call(console.warn, console),
|
|
error: Function.prototype.bind.call(console.error, 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)
|
|
};
|
|
|
|
logLevel.setLogLevel = function (newLevel) {
|
|
if (newLevel) {
|
|
Object.keys(logLevel).forEach(function (key) {
|
|
if (!newLevel.includes(key.toLocaleUpperCase())) {
|
|
logLevel[key] = function () {};
|
|
}
|
|
});
|
|
}
|
|
};
|
|
} else {
|
|
logLevel = {
|
|
debug () {},
|
|
log () {},
|
|
info () {},
|
|
warn () {},
|
|
error () {},
|
|
group () {},
|
|
groupCollapsed () {},
|
|
groupEnd () {},
|
|
time () {},
|
|
timeEnd () {},
|
|
timeStamp () {}
|
|
};
|
|
|
|
logLevel.setLogLevel = function () {};
|
|
}
|
|
|
|
return logLevel;
|
|
}));
|