-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INTERNAL] logger: Implement isLevelEnabled
- Loading branch information
1 parent
8f65d3f
commit 81cd803
Showing
1 changed file
with
14 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}". ` + | ||
|
@@ -25,7 +25,19 @@ class Logger { | |
} | ||
|
||
isLevelEnabled(levelName) { | ||
return true; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kristian
|
||
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) { | ||
|
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