Introduce different log levels
This commit is contained in:
parent
fe4ccec4e2
commit
82d404a973
|
@ -5,6 +5,7 @@ const addDays = require("date-fns/add_days");
|
||||||
const db = require("./utils/data");
|
const db = require("./utils/data");
|
||||||
const isValidPackageName = require("./utils/isValidPackageName");
|
const isValidPackageName = require("./utils/isValidPackageName");
|
||||||
const parsePackageURL = require("./utils/parsePackageURL");
|
const parsePackageURL = require("./utils/parsePackageURL");
|
||||||
|
const logging = require("./utils/logging");
|
||||||
|
|
||||||
const CloudflareAPI = require("./CloudflareAPI");
|
const CloudflareAPI = require("./CloudflareAPI");
|
||||||
const StatsAPI = require("./StatsAPI");
|
const StatsAPI = require("./StatsAPI");
|
||||||
|
@ -157,8 +158,8 @@ function ingestLogsForZone(zone, startDate, endDate) {
|
||||||
).then(stream => {
|
).then(stream => {
|
||||||
const endFetchTime = Date.now();
|
const endFetchTime = Date.now();
|
||||||
|
|
||||||
console.log(
|
logging.info(
|
||||||
"info: Fetched logs for %s from %s to %s (%dms)",
|
"Fetched logs for %s from %s to %s (%dms)",
|
||||||
zone.name,
|
zone.name,
|
||||||
stringifySeconds(startSeconds),
|
stringifySeconds(startSeconds),
|
||||||
stringifySeconds(endSeconds),
|
stringifySeconds(endSeconds),
|
||||||
|
@ -170,8 +171,8 @@ function ingestLogsForZone(zone, startDate, endDate) {
|
||||||
return processLogs(stream).then(totalEntries => {
|
return processLogs(stream).then(totalEntries => {
|
||||||
const endProcessTime = Date.now();
|
const endProcessTime = Date.now();
|
||||||
|
|
||||||
console.log(
|
logging.info(
|
||||||
"info: Processed %d log entries for %s (%dms)",
|
"Processed %d log entries for %s (%dms)",
|
||||||
totalEntries,
|
totalEntries,
|
||||||
zone.name,
|
zone.name,
|
||||||
endProcessTime - startProcessTime
|
endProcessTime - startProcessTime
|
||||||
|
|
|
@ -5,13 +5,16 @@ const tar = require("tar-stream");
|
||||||
|
|
||||||
const bufferStream = require("./bufferStream");
|
const bufferStream = require("./bufferStream");
|
||||||
const agent = require("./registryAgent");
|
const agent = require("./registryAgent");
|
||||||
|
const logging = require("./logging");
|
||||||
|
|
||||||
function fetchNpmPackage(packageConfig) {
|
function fetchNpmPackage(packageConfig) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const tarballURL = packageConfig.dist.tarball;
|
const tarballURL = packageConfig.dist.tarball;
|
||||||
|
|
||||||
console.log(
|
logging.debug(
|
||||||
`info: Fetching package for ${packageConfig.name} from ${tarballURL}`
|
"Fetching package for %s from %s",
|
||||||
|
packageConfig.name,
|
||||||
|
tarballURL
|
||||||
);
|
);
|
||||||
|
|
||||||
const { hostname, pathname } = url.parse(tarballURL);
|
const { hostname, pathname } = url.parse(tarballURL);
|
||||||
|
|
|
@ -4,6 +4,7 @@ const https = require("https");
|
||||||
const serverConfig = require("../serverConfig");
|
const serverConfig = require("../serverConfig");
|
||||||
const bufferStream = require("./bufferStream");
|
const bufferStream = require("./bufferStream");
|
||||||
const agent = require("./registryAgent");
|
const agent = require("./registryAgent");
|
||||||
|
const logging = require("./logging");
|
||||||
|
|
||||||
function parseJSON(res) {
|
function parseJSON(res) {
|
||||||
return bufferStream(res).then(JSON.parse);
|
return bufferStream(res).then(JSON.parse);
|
||||||
|
@ -18,9 +19,7 @@ function fetchNpmPackageInfo(packageName) {
|
||||||
|
|
||||||
const infoURL = `${serverConfig.registryURL}/${encodedPackageName}`;
|
const infoURL = `${serverConfig.registryURL}/${encodedPackageName}`;
|
||||||
|
|
||||||
console.log(
|
logging.debug("Fetching package info for %s from %s", packageName, infoURL);
|
||||||
`info: Fetching package info for ${packageName} from ${infoURL}`
|
|
||||||
);
|
|
||||||
|
|
||||||
const { hostname, pathname } = url.parse(infoURL);
|
const { hostname, pathname } = url.parse(infoURL);
|
||||||
const options = {
|
const options = {
|
||||||
|
|
|
@ -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
|
||||||
|
};
|
Loading…
Reference in New Issue