Skip to content

Commit

Permalink
[INTERNAL] logger: Implement isLevelEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Mar 21, 2019
1 parent 8f65d3f commit 81cd803
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const npmlog = require("npmlog");

const levels = ["silly", "verbose", "info", "warn", "error"];
if (process.env.UI5_LOG_LVL) {
const levels = ["silly", "verbose", "info", "warn", "error"];
const logLvl = process.env.UI5_LOG_LVL;
if (!levels.includes(logLvl)) {
throw new Error(`UI5 Logger: Environment variable UI5_LOG_LVL is set to an unkown log level "${logLvl}". ` +
Expand All @@ -25,7 +25,19 @@ class Logger {
}

isLevelEnabled(levelName) {
return true;

This comment has been minimized.

Copy link
@kristian

kristian Oct 11, 2019

isLevelEnabled should check and return w/ true, in case the special log level "silent" is set. See [1].

[1] https://github.com/npm/npmlog#loglevel

This comment has been minimized.

Copy link
@kristian

kristian Oct 11, 2019

Causes the following exception if "silent" is set:

 Error: Failed to find current log level silent in list of expected log levels
    at Logger.isLevelEnabled (node_modules\@ui5\logger\lib\logger.js:31:10)
    at NpmTranslator.processPkg (node_modules\@ui5\project\lib\translators\npm.js:86:12)

This comment has been minimized.

Copy link
@RandomByte

RandomByte Oct 11, 2019

Author Member

Thanks! Will be fixed with #136

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;
}
}

silly(...messages) {
Expand Down

0 comments on commit 81cd803

Please sign in to comment.