Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

logger4node

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logger4node - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

2

index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc