backfill-generic-logger
Advanced tools
Comparing version 3.0.0-alpha.0 to 3.0.0
export declare const logLevelObject: { | ||
error: string; | ||
warn: string; | ||
info: string; | ||
verbose: string; | ||
silly: string; | ||
error: string; | ||
warn: string; | ||
info: string; | ||
verbose: string; | ||
silly: string; | ||
}; | ||
export declare type LogLevels = keyof typeof logLevelObject; | ||
export declare function isCorrectLogLevel( | ||
logLevel: string | ||
): logLevel is LogLevels; | ||
export declare function isCorrectLogLevel(logLevel: string): logLevel is LogLevels; | ||
export declare function setLogLevel(newLogLevel: LogLevels): void; | ||
export interface Logger { | ||
silly(...args: any[]): void; | ||
verbose(...args: any[]): void; | ||
info(...args: any[]): void; | ||
warn(...args: any[]): void; | ||
error(...args: any[]): void; | ||
profile(marker: string, ...args: any[]): number | void; | ||
silly(...args: any[]): void; | ||
verbose(...args: any[]): void; | ||
info(...args: any[]): void; | ||
warn(...args: any[]): void; | ||
error(...args: any[]): void; | ||
profile(marker: string, ...args: any[]): number | void; | ||
} | ||
export declare const logger: Logger; | ||
//# sourceMappingURL=index.d.ts.map | ||
//# sourceMappingURL=index.d.ts.map |
120
lib/index.js
@@ -5,13 +5,13 @@ "use strict"; | ||
function logInternal(method, symbol, ...args) { | ||
console[method]("backfill:", symbol, ...args); | ||
console[method]("backfill:", symbol, ...args); | ||
} | ||
exports.logLevelObject = { | ||
error: "", | ||
warn: "", | ||
info: "", | ||
verbose: "", | ||
silly: "" | ||
error: "", | ||
warn: "", | ||
info: "", | ||
verbose: "", | ||
silly: "" | ||
}; | ||
function isCorrectLogLevel(logLevel) { | ||
return exports.logLevelObject.hasOwnProperty(logLevel); | ||
return exports.logLevelObject.hasOwnProperty(logLevel); | ||
} | ||
@@ -21,67 +21,61 @@ exports.isCorrectLogLevel = isCorrectLogLevel; | ||
function setLogLevel(newLogLevel) { | ||
logLevel = newLogLevel; | ||
logLevel = newLogLevel; | ||
} | ||
exports.setLogLevel = setLogLevel; | ||
function logLevelNumber(logLevel) { | ||
switch (logLevel) { | ||
case "error": | ||
return 0; | ||
case "warn": | ||
return 1; | ||
case "info": | ||
return 2; | ||
case "verbose": | ||
return 3; | ||
case "silly": | ||
return 4; | ||
} | ||
switch (logLevel) { | ||
case "error": | ||
return 0; | ||
case "warn": | ||
return 1; | ||
case "info": | ||
return 2; | ||
case "verbose": | ||
return 3; | ||
case "silly": | ||
return 4; | ||
} | ||
} | ||
const performanceMarkers = {}; | ||
exports.logger = { | ||
silly(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("silly")) { | ||
logInternal("info", chalk.gray("\u25C7"), ...args); | ||
} | ||
}, | ||
verbose(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("verbose")) { | ||
logInternal("info", "\u25a1", ...args); | ||
} | ||
}, | ||
info(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("info")) { | ||
logInternal("info", chalk.blue.bold("\u25a0"), ...args); | ||
} | ||
}, | ||
warn(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("warn")) { | ||
logInternal("warn", chalk.yellow.bold("\u25B2"), ...args); | ||
} | ||
}, | ||
error(...args) { | ||
logInternal("error", chalk.redBright("x"), ...args); | ||
}, | ||
profile(marker, ...args) { | ||
if (!performanceMarkers[marker]) { | ||
performanceMarkers[marker] = process.hrtime(); | ||
} else { | ||
const delta = process.hrtime(performanceMarkers[marker]); | ||
delete performanceMarkers[marker]; | ||
if (delta) { | ||
const ms = Math.round(delta[0] * 1000 + delta[1] / 1000000); | ||
silly(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("silly")) { | ||
logInternal("info", chalk.gray("\u25C7"), ...args); | ||
} | ||
}, | ||
verbose(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("verbose")) { | ||
logInternal( | ||
"info", | ||
chalk.cyan("\u2023"), | ||
`Profiling ${chalk.underline(marker)} took ${chalk.cyanBright( | ||
`${ms}ms` | ||
)}`, | ||
...args | ||
); | ||
logInternal("info", "\u25a1", ...args); | ||
} | ||
return ms; | ||
} | ||
}, | ||
info(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("info")) { | ||
logInternal("info", chalk.blue.bold("\u25a0"), ...args); | ||
} | ||
}, | ||
warn(...args) { | ||
if (logLevelNumber(logLevel) >= logLevelNumber("warn")) { | ||
logInternal("warn", chalk.yellow.bold("\u25B2"), ...args); | ||
} | ||
}, | ||
error(...args) { | ||
logInternal("error", chalk.redBright("x"), ...args); | ||
}, | ||
profile(marker, ...args) { | ||
if (!performanceMarkers[marker]) { | ||
performanceMarkers[marker] = process.hrtime(); | ||
} | ||
else { | ||
const delta = process.hrtime(performanceMarkers[marker]); | ||
delete performanceMarkers[marker]; | ||
if (delta) { | ||
const ms = Math.round(delta[0] * 1000 + delta[1] / 1000000); | ||
if (logLevelNumber(logLevel) >= logLevelNumber("verbose")) { | ||
logInternal("info", chalk.cyan("\u2023"), `Profiling ${chalk.underline(marker)} took ${chalk.cyanBright(`${ms}ms`)}`, ...args); | ||
} | ||
return ms; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwrQkFBZ0M7QUFFaEMsU0FBUyxXQUFXLENBQ2xCLE1BQWlDLEVBQ2pDLE1BQWMsRUFDZCxHQUFHLElBQVc7SUFFZCxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUMsV0FBVyxFQUFFLE1BQU0sRUFBRSxHQUFHLElBQUksQ0FBQyxDQUFDO0FBQ2hELENBQUM7QUFFWSxRQUFBLGNBQWMsR0FBRztJQUM1QixLQUFLLEVBQUUsRUFBRTtJQUNULElBQUksRUFBRSxFQUFFO0lBQ1IsSUFBSSxFQUFFLEVBQUU7SUFDUixPQUFPLEVBQUUsRUFBRTtJQUNYLEtBQ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TUFBTSxFQUFFLENBQUM7U0FDL0M7YUFBTTtZQUNMLE1BQU0sS0FBSyxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsa0JBQWtCLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztZQUN6RCxPQUFPLGtCQUFrQixDQUFDLE1BQU0sQ0FBQyxDQUFDO1lBRWxDLElBQUksS0FBSyxFQUFFO2dCQUNULE1BQU0sRUFBRSxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxHQUFHLElBQUksR0FBRyxLQUFLLENBQUMsQ0FBQyxDQUFDLEdBQUcsT0FBTyxDQUFDLENBQUM7Z0JBRTVELElBQUksY0FBYyxDQUFDLFFBQVEsQ0FBQyxJQUFJLGNBQWMsQ0FBQyxTQUFTLENBQUMsRUFBRTtvQkFDekQsV0FBVyxDQUNULE1BQU0sRUFDTixLQUFLLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxFQUNwQixhQUFhLEtBQUssQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLFNBQVMsS0FBSyxDQUFDLFVBQVUsQ0FDM0QsR0FBRyxFQUFFLElBQUksQ0FDVixFQUFFLEVBQ0gsR0FBRyxJQUFJLENBQ1IsQ0FBQztpQkFDSDtnQkFFRCxPQUFPLEVBQUUsQ0FBQzthQUNYO1NBQ0Y7SUFDSCxDQUFDO0NBQ0YsQ0FBQyJ9 |
@@ -10,3 +10,3 @@ { | ||
}, | ||
"version": "3.0.0-alpha.0", | ||
"version": "3.0.0", | ||
"main": "lib/index.js", | ||
@@ -25,3 +25,3 @@ "scripts": { | ||
}, | ||
"gitHead": "ae883801bc531345c3e44d372788768b92e83b34" | ||
"gitHead": "7542473ba460ad74c0f6373e5e187528b219023c" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
127573
1
0
196