mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-22 05:07:05 +00:00
Rework logging colors (#3350)
- Replacing old package `colors` by drop-in replacement `ansis`
- Rework `console-stamp` config to show all Log outputs in same color
(errors = red, warnings = yellow, debug = blue background (only for the
label), info = blue)
- This also fixes `npm run config:check` (broken since
6097547c10
)
Feel free to let me know if the PR is too big and you want me to do
individual PRs for the changes.
Before:

After:

---------
Co-authored-by: Veeck <github@veeck.de>
This commit is contained in:
committed by
GitHub
parent
098757f248
commit
6dbacbb773
33
js/logger.js
33
js/logger.js
@@ -10,10 +10,39 @@
|
||||
(function (root, factory) {
|
||||
if (typeof exports === "object") {
|
||||
if (process.env.JEST_WORKER_ID === undefined) {
|
||||
const colors = require("ansis");
|
||||
|
||||
// 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"]
|
||||
format: ":date(yyyy-mm-dd HH:MM:ss.l) :label(7) :msg",
|
||||
tokens: {
|
||||
label: (arg) => {
|
||||
const { method, defaultTokens } = arg;
|
||||
let label = defaultTokens.label(arg);
|
||||
if (method === "error") {
|
||||
label = colors.red(label);
|
||||
} else if (method === "warn") {
|
||||
label = colors.yellow(label);
|
||||
} else if (method === "debug") {
|
||||
label = colors.bgBlue(label);
|
||||
} else if (method === "info") {
|
||||
label = colors.blue(label);
|
||||
}
|
||||
return label;
|
||||
},
|
||||
msg: (arg) => {
|
||||
const { method, defaultTokens } = arg;
|
||||
let msg = defaultTokens.msg(arg);
|
||||
if (method === "error") {
|
||||
msg = colors.red(msg);
|
||||
} else if (method === "warn") {
|
||||
msg = colors.yellow(msg);
|
||||
} else if (method === "info") {
|
||||
msg = colors.blue(msg);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Node, CommonJS-like
|
||||
|
Reference in New Issue
Block a user