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.1.0 to 1.0.0

src/test.spec.d.ts

60

package.json
{
"name": "logger4node",
"version": "0.1.0",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "NODE_ENV=test node_modules/.bin/mocha './src/**/*.spec.ts'",
"coverage": "nyc mocha './src/**/*.spec.ts' && nyc report --reporter=text-lcov > coverage1.lcov"
},

@@ -24,17 +25,50 @@ "repository": {

"devDependencies": {
"@types/debug": "^4.1.5",
"@types/node": "^15.12.4",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"eslint": "^7.29.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-promise": "^5.1.0",
"@types/chai": "^4.3.1",
"@types/debug": "^4.1.7",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.4",
"@types/sinon": "^10.0.12",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"chai": "^4.3.6",
"eslint": "^8.19.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-typescript": "^0.14.0",
"mocha": "^10.0.0",
"node-tslint-rules": "^1.20.3",
"ts-node": "^10.0.0",
"nyc": "^15.1.0",
"sinon": "^14.0.0",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"typescript": "^4.3.4"
"typescript": "^4.7.4"
},
"nyc": {
"include": [
"server/**/*.ts"
],
"exclude": [
"server/**/*.spec.ts",
"node_modules"
],
"extension": [
".ts"
],
"sourceMap": true,
"instrument": true,
"fullTrace": true
},
"mocha": {
"color": true,
"ui": "bdd",
"recursive": true,
"timeout": 20000,
"require": [
"ts-node/register/transpile-only"
],
"reporter": "dot",
"exit": true
}
}

@@ -0,1 +1,4 @@

![build](https://github.com/yog27ray/logger4node/actions/workflows/node.js.yml/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/yog27ray/logger4node/branch/master/graph/badge.svg)](https://codecov.io/gh/yog27ray/logger4node)
##Logger for Node

@@ -8,9 +8,10 @@ export declare const enum LogSeverity {

}
export declare const LogLevel: {
[key in LogSeverity]: number;
};
export declare function setLogLevel(logSeverity: LogSeverity): void;
export declare function setLogPattern(pattern: string): void;
export declare function setLogSeverityPattern(level: LogSeverity, pattern: string): void;
export declare class Logger {
private name;
private static LOG_LEVEL_ENABLED;
private enabled;
static matches(value: string): boolean;
static doesNotMatches(value: string): boolean;
private static isLogEnabled;
private readonly name;
verbose(formatter: unknown, ...args: Array<unknown>): void;

@@ -21,4 +22,5 @@ info(formatter: unknown, ...args: Array<unknown>): void;

error(formatter: unknown, ...args: Array<unknown>): void;
log(logSeverity: LogSeverity, formatter: unknown, ...args: Array<unknown>): void;
constructor(name: string);
private isLogEnabled;
private log;
}

@@ -6,5 +6,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
exports.Logger = exports.setLogSeverityPattern = exports.setLogPattern = exports.setLogLevel = exports.LogLevel = void 0;
const util_1 = __importDefault(require("util"));
const LogLevel = {
exports.LogLevel = {
verbose: 1,

@@ -26,54 +26,92 @@ info: 2,

};
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;
function generateMatchAndDoesNotMatchArray(input = '') {
const positive = [];
const negative = [];
input.split(',').forEach((key_) => {
let key = key_;
let operator = '+';
if (key[0] === '-') {
operator = '-';
key = key.substr(1, key.length);
}
default: {
matches.push(key);
key = key.replace(/\*/g, '.*');
switch (operator) {
case '-': {
negative.push(key);
return;
}
default: {
positive.push(key);
}
}
}
});
});
return [positive, negative];
}
let positive = [];
let negative = [];
let minLogLevelEnabled = exports.LogLevel.debug;
const LOG_PATTERN = {
["verbose" /* LogSeverity.VERBOSE */]: { positive: [], negative: [] },
["info" /* LogSeverity.INFO */]: { positive: [], negative: [] },
["warn" /* LogSeverity.WARN */]: { positive: [], negative: [] },
["debug" /* LogSeverity.DEBUG */]: { positive: [], negative: [] },
["error" /* LogSeverity.ERROR */]: { positive: [], negative: [] },
};
function isNotMatchWithPatterns(patterns, value) {
return patterns.every((pattern) => !new RegExp(`^${pattern}$`).test(value));
}
function isMatchWithPatterns(patterns, value) {
return patterns.some((pattern) => new RegExp(`^${pattern}$`).test(value));
}
function setLogLevel(logSeverity) {
minLogLevelEnabled = exports.LogLevel[logSeverity] || exports.LogLevel["debug" /* LogSeverity.DEBUG */];
}
exports.setLogLevel = setLogLevel;
function setLogPattern(pattern) {
([positive, negative] = generateMatchAndDoesNotMatchArray(pattern));
}
exports.setLogPattern = setLogPattern;
function setLogSeverityPattern(level, pattern) {
([LOG_PATTERN[level].positive, LOG_PATTERN[level].negative] = pattern ? generateMatchAndDoesNotMatchArray(pattern) : [[], []]);
}
exports.setLogSeverityPattern = setLogSeverityPattern;
class Logger {
constructor(name) {
this.name = name;
this.enabled = false;
this.enabled = Logger.matches(name) && !Logger.doesNotMatches(name);
}
static matches(value) {
return matches.some((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);
}
verbose(formatter, ...args) {
this.log("verbose" /* VERBOSE */, formatter, ...args);
this.log("verbose" /* LogSeverity.VERBOSE */, formatter, ...args);
}
info(formatter, ...args) {
this.log("info" /* INFO */, formatter, ...args);
this.log("info" /* LogSeverity.INFO */, formatter, ...args);
}
warn(formatter, ...args) {
this.log("warn" /* WARN */, formatter, ...args);
this.log("warn" /* LogSeverity.WARN */, formatter, ...args);
}
debug(formatter, ...args) {
this.log("debug" /* DEBUG */, formatter, ...args);
this.log("debug" /* LogSeverity.DEBUG */, formatter, ...args);
}
error(formatter, ...args) {
this.log("error" /* ERROR */, formatter, ...args);
this.log("error" /* LogSeverity.ERROR */, formatter, ...args);
}
isLogEnabled(logSeverity) {
if (!isNotMatchWithPatterns(LOG_PATTERN[logSeverity].negative, this.name)) {
return false;
}
if (isMatchWithPatterns(LOG_PATTERN[logSeverity].positive, this.name)) {
return true;
}
if (exports.LogLevel[logSeverity] < minLogLevelEnabled) {
return false;
}
if (!isNotMatchWithPatterns(negative, this.name)) {
return false;
}
if (isMatchWithPatterns(positive, this.name)) {
return true;
}
return false;
}
log(logSeverity, formatter, ...args) {
if (!Logger.isLogEnabled(logSeverity) || !this.enabled) {
if (!this.isLogEnabled(logSeverity)) {
return;

@@ -85,9 +123,2 @@ }

exports.Logger = Logger;
Logger.LOG_LEVEL_ENABLED = [
"verbose" /* VERBOSE */,
"info" /* INFO */,
"warn" /* WARN */,
"debug" /* DEBUG */,
"error" /* ERROR */,
].filter((logLevel) => (LogLevel[process.env.DEBUG_LEVEL] || LogLevel["debug" /* DEBUG */]) <= LogLevel[logLevel]);
//# sourceMappingURL=logger.js.map

@@ -1,6 +0,9 @@

import { Logger } from './logger';
import { Logger, LogSeverity } from './logger';
export declare class Logger4Node {
private readonly _applicationName;
static setLogLevel(logSeverity: LogSeverity): void;
static setLogPattern(pattern: string): void;
static setLogSeverityPattern(level: LogSeverity, pattern: string): void;
constructor(applicationName: string);
instance(name: string): Logger;
}

@@ -9,2 +9,11 @@ "use strict";

}
static setLogLevel(logSeverity) {
(0, logger_1.setLogLevel)(logSeverity);
}
static setLogPattern(pattern) {
(0, logger_1.setLogPattern)(pattern);
}
static setLogSeverityPattern(level, pattern) {
(0, logger_1.setLogSeverityPattern)(level, pattern);
}
instance(name) {

@@ -15,2 +24,6 @@ return new logger_1.Logger(`${this._applicationName}:${name}`);

exports.Logger4Node = Logger4Node;
Logger4Node.setLogLevel(process.env.DEBUG_LEVEL);
Logger4Node.setLogPattern(process.env.DEBUG);
Object.keys(logger_1.LogLevel)
.forEach((logSeverity) => Logger4Node.setLogSeverityPattern(logSeverity, process.env[`LOG_${logSeverity.toUpperCase()}`]));
//# sourceMappingURL=logger4-node.js.map

Sorry, the diff of this file is not supported yet

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