Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Fix handling of log level "silent" #136

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const npmlog = require("npmlog");

const levels = ["silly", "verbose", "info", "warn", "error"];
const levels = ["silly", "verbose", "info", "warn", "error", "silent"];
if (process.env.UI5_LOG_LVL) {
const logLvl = process.env.UI5_LOG_LVL;
if (!levels.includes(logLvl)) {
Expand All @@ -18,26 +18,30 @@ npmlog.on("error", (err) => {
console.log(err);
});

function isLevelEnabled(levelName) {
const currIdx = levels.indexOf(npmlog.level);
const reqIdx = levels.indexOf(levelName);
if (currIdx === -1) {
throw new Error(`Failed to find current log level "${npmlog.level}"" in list of expected log levels`);
}
if (reqIdx === -1) {
throw new Error(`Unkown log level "${levelName}"`);
}
if (reqIdx >= currIdx) {
return true;
} else {
return false;
}
}

class Logger {
constructor(moduleName) {
this._moduleName = moduleName;
this._logger = npmlog;
}

isLevelEnabled(levelName) {
const currIdx = levels.indexOf(npmlog.level);
const reqIdx = levels.indexOf(levelName);
if (currIdx === -1) {
throw new Error(`Failed to find current log level ${npmlog.level} in list of expected log levels`);
}
if (reqIdx === -1) {
throw new Error(`Unkown log level "${levelName}"`);
}
if (reqIdx >= currIdx) {
return true;
} else {
return false;
}
return isLevelEnabled(levelName);
}

silly(...messages) {
Expand Down Expand Up @@ -129,9 +133,14 @@ module.exports = {
},

setLevel(level) {
if (!levels.includes(level)) {
throw new Error(`Unkown log level "${level}"`);
}
return npmlog.level = level;
},

isLevelEnabled,

setShowProgress(showProgress) {
if (showProgress) {
npmlog.enableProgress();
Expand Down