Skip to content

Commit

Permalink
fix: make warning and error level output prefix consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed May 13, 2020
1 parent 59994e0 commit 5e8bbbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ const fetchPackageDependencies = async function({ name, version, deep }) {
// handle version not exist
if (!versions.find(x => x == entry.version)) {
log.warn(
`[WARN] package ${entry.name}@${
`package ${entry.name}@${
entry.version
} is not a valid choice of ${versions.reverse().join(", ")}`
);
// eslint-disable-next-line require-atomic-updates
validDep.version = entry.version = getLatestVersion(pkgInfo);
log.warn(`[WARN] fall back to ${entry.name}@${entry.version}`);
log.warn(`fall back to ${entry.name}@${entry.version}`);
}
// add dependencies to pending list
if (validDep.self || deep) {
Expand Down
12 changes: 11 additions & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
const log = require("loglevel");
const prefix = require("loglevel-plugin-prefix");

prefix.reg(log);
if (process.env.NODE_ENV == "test") {
prefix.reg(log);
prefix.apply(log, {
// eslint-disable-next-line no-unused-vars
format(level, name, timestamp) {
return "[test]";
}
});
} else {
prefix.apply(log, {
// eslint-disable-next-line no-unused-vars
format(level, name, timestamp) {
if (level == "ERROR" || level == "WARN") {
return `[${level}]`;
}
return "";
}
});
}

module.exports = log;

0 comments on commit 5e8bbbb

Please sign in to comment.