mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Provide a create package for the clusterio npm org which gathers the necessary details to install a working cluster either as standalone or as separate nodes.
52 lines
1012 B
JavaScript
52 lines
1012 B
JavaScript
/* eslint-disable no-console */
|
|
"use strict";
|
|
const chalk = require("chalk");
|
|
|
|
const levels = Object.freeze({
|
|
fatal: 0,
|
|
error: 1,
|
|
warn: 2,
|
|
audit: 3,
|
|
info: 4,
|
|
verbose: 6,
|
|
});
|
|
|
|
const colors = {
|
|
fatal: "inverse red",
|
|
error: "bold redBright",
|
|
warn: "bold yellowBright",
|
|
audit: "bold greenBright",
|
|
info: "bold blueBright",
|
|
verbose: "bold grey",
|
|
};
|
|
|
|
let maxLogLevel = levels.info;
|
|
const logger = {};
|
|
for (let [name, level] of Object.entries(levels)) {
|
|
// eslint-disable-next-line no-loop-func
|
|
logger[name] = message => {
|
|
if (level > maxLogLevel) {
|
|
return;
|
|
}
|
|
let style = chalk;
|
|
for (let part of colors[name].split(" ")) {
|
|
style = style[part];
|
|
}
|
|
if (["fatal", "error"].includes(name)) {
|
|
console.error(`${style(name)} ${message}`);
|
|
} else if (["warn"].includes(name)) {
|
|
console.warn(`${style(name)} ${message}`);
|
|
} else {
|
|
console.log(`${style(name)} ${message}`);
|
|
}
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
colors,
|
|
levels,
|
|
setLogLevel: (level) => { maxLogLevel = level; },
|
|
logger,
|
|
};
|
|
|