Introduce different log levels
This commit is contained in:
@ -5,13 +5,16 @@ const tar = require("tar-stream");
|
||||
|
||||
const bufferStream = require("./bufferStream");
|
||||
const agent = require("./registryAgent");
|
||||
const logging = require("./logging");
|
||||
|
||||
function fetchNpmPackage(packageConfig) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const tarballURL = packageConfig.dist.tarball;
|
||||
|
||||
console.log(
|
||||
`info: Fetching package for ${packageConfig.name} from ${tarballURL}`
|
||||
logging.debug(
|
||||
"Fetching package for %s from %s",
|
||||
packageConfig.name,
|
||||
tarballURL
|
||||
);
|
||||
|
||||
const { hostname, pathname } = url.parse(tarballURL);
|
||||
|
@ -4,6 +4,7 @@ const https = require("https");
|
||||
const serverConfig = require("../serverConfig");
|
||||
const bufferStream = require("./bufferStream");
|
||||
const agent = require("./registryAgent");
|
||||
const logging = require("./logging");
|
||||
|
||||
function parseJSON(res) {
|
||||
return bufferStream(res).then(JSON.parse);
|
||||
@ -18,9 +19,7 @@ function fetchNpmPackageInfo(packageName) {
|
||||
|
||||
const infoURL = `${serverConfig.registryURL}/${encodedPackageName}`;
|
||||
|
||||
console.log(
|
||||
`info: Fetching package info for ${packageName} from ${infoURL}`
|
||||
);
|
||||
logging.debug("Fetching package info for %s from %s", packageName, infoURL);
|
||||
|
||||
const { hostname, pathname } = url.parse(infoURL);
|
||||
const options = {
|
||||
|
24
modules/utils/logging.js
Normal file
24
modules/utils/logging.js
Normal file
@ -0,0 +1,24 @@
|
||||
const log = console.log.bind(console);
|
||||
|
||||
function noop() {}
|
||||
|
||||
let debug, info, warn;
|
||||
|
||||
if (process.env.LOG_LEVEL === "none") {
|
||||
debug = info = warn = noop;
|
||||
} else if (process.env.LOG_LEVEL === "debug") {
|
||||
debug = info = warn = log;
|
||||
} else if (process.env.LOG_LEVEL === "warn") {
|
||||
debug = info = noop;
|
||||
warn = log;
|
||||
} else {
|
||||
// default LOG_LEVEL = "info"
|
||||
debug = noop;
|
||||
info = warn = log;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
debug,
|
||||
info,
|
||||
warn
|
||||
};
|
Reference in New Issue
Block a user