Make logger configurable

This commit is contained in:
Veeck 2020-05-11 07:46:56 +02:00 committed by rejas
parent f2d03a511e
commit d0c6a4ee6d
2 changed files with 14 additions and 2 deletions

View File

@ -28,6 +28,7 @@ var config = {
httpsCertificate: "", // HTTPS Certificate path, only require when useHttps is true httpsCertificate: "", // HTTPS Certificate path, only require when useHttps is true
language: "en", language: "en",
logLevel: ["INFO", "LOG", "WARN", "ERROR"],
timeFormat: 24, timeFormat: 24,
units: "metric", units: "metric",
// serverOnly: true/false/"local" , // serverOnly: true/false/"local" ,

View File

@ -18,7 +18,8 @@
root.Log = factory(root.config); root.Log = factory(root.config);
} }
}(this, function (config) { }(this, function (config) {
return {
let logLevel = {
info: Function.prototype.bind.call(console.info, console), info: Function.prototype.bind.call(console.info, console),
log: Function.prototype.bind.call(console.log, console), log: Function.prototype.bind.call(console.log, console),
error: Function.prototype.bind.call(console.error, console), error: Function.prototype.bind.call(console.error, console),
@ -29,5 +30,15 @@
time: Function.prototype.bind.call(console.time, console), time: Function.prototype.bind.call(console.time, console),
timeEnd: Function.prototype.bind.call(console.timeEnd, console), timeEnd: Function.prototype.bind.call(console.timeEnd, console),
timeStamp: Function.prototype.bind.call(console.timeStamp, 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;
})); }));