logger4node
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -1,3 +0,3 @@ | ||
import { LogSeverity } from 'src/logger'; | ||
import { LogSeverity } from './src/logger'; | ||
import { Logger4Node } from './src/logger4-node'; | ||
export { Logger4Node, LogSeverity }; |
{ | ||
"name": "logger4node", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"debug": "^4.3.1" | ||
"util": "^0.12.3" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
@@ -1,2 +0,1 @@ | ||
import { Debugger } from 'debug'; | ||
export declare const enum LogSeverity { | ||
@@ -10,6 +9,8 @@ VERBOSE = "verbose", | ||
export declare class Logger { | ||
private name; | ||
private static LOG_LEVEL_ENABLED; | ||
private readonly _debugLogger; | ||
private enabled; | ||
static matches(value: string): boolean; | ||
static doesNotMatches(value: string): boolean; | ||
private static isLogEnabled; | ||
get debugLogger(): Debugger; | ||
verbose(formatter: unknown, ...args: Array<unknown>): void; | ||
@@ -16,0 +17,0 @@ info(formatter: unknown, ...args: Array<unknown>): void; |
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.Logger = void 0; | ||
const debug_1 = __importDefault(require("debug")); | ||
const util_1 = __importDefault(require("util")); | ||
const LogLevel = { | ||
@@ -16,12 +16,49 @@ verbose: 1, | ||
}; | ||
const Color = { | ||
severity: '\x1b[33m', | ||
application: '\x1b[36m', | ||
reset: '\x1b[0m', | ||
verbose: '\x1b[37m', | ||
info: '\x1b[35m', | ||
warn: '\x1b[33m', | ||
debug: '\x1b[34m', | ||
error: '\x1b[31m', | ||
}; | ||
const matches = []; | ||
const doesNotMatches = []; | ||
(process.env.DEBUG || '*').split(',').forEach((key_) => { | ||
let key = key_; | ||
let operator = '+'; | ||
if (key[0] === '-') { | ||
operator = '-'; | ||
key = key.substr(1, key.length); | ||
} | ||
key = key.replace(new RegExp('\\*', 'g'), '.*'); | ||
switch (operator) { | ||
case '-': { | ||
doesNotMatches.push(key); | ||
return; | ||
} | ||
default: { | ||
matches.push(key); | ||
} | ||
} | ||
}); | ||
console.log('!!', matches); | ||
console.log('!!a', doesNotMatches); | ||
class Logger { | ||
constructor(name) { | ||
this._debugLogger = debug_1.default(name); | ||
this.name = name; | ||
this.enabled = false; | ||
this.enabled = Logger.matches(name) && !Logger.doesNotMatches(name); | ||
} | ||
static matches(value) { | ||
return matches.every((pattern) => new RegExp(`^${pattern}$`).test(value)); | ||
} | ||
static doesNotMatches(value) { | ||
return doesNotMatches.some((pattern) => new RegExp(`^${pattern}$`).test(value)); | ||
} | ||
static isLogEnabled(logSeverity) { | ||
return Logger.LOG_LEVEL_ENABLED.includes(logSeverity); | ||
} | ||
get debugLogger() { | ||
return this._debugLogger; | ||
} | ||
verbose(formatter, ...args) { | ||
@@ -43,6 +80,6 @@ this.log("verbose" /* VERBOSE */, formatter, ...args); | ||
log(logSeverity, formatter, ...args) { | ||
if (!Logger.isLogEnabled(logSeverity)) { | ||
if (!Logger.isLogEnabled(logSeverity) || !this.enabled) { | ||
return; | ||
} | ||
this._debugLogger(formatter, ...args, logSeverity); | ||
console.log(Color.severity, logSeverity, Color.application, this.name, Color[logSeverity], util_1.default.format(formatter, ...args), Color.reset); | ||
} | ||
@@ -49,0 +86,0 @@ } |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
9132
140
2
+ Addedutil@^0.12.3
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.1.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedwhich-typed-array@1.1.16(transitive)
- Removeddebug@^4.3.1
- Removeddebug@4.3.7(transitive)
- Removedms@2.1.3(transitive)