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 1.0.16 to 1.0.17

spec/test-json.spec.d.ts

10

package.json
{
"name": "logger4node",
"version": "1.0.16",
"version": "1.0.17",
"description": "",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test node_modules/.bin/mocha './src/**/*.spec.ts'",
"coverage": "nyc mocha './src/**/*.spec.ts' && nyc report --reporter=text-lcov > coverage1.lcov"
"test": "NODE_ENV=test node_modules/.bin/mocha './spec/**/*.spec.ts'",
"coverage": "nyc mocha './spec/**/*.spec.ts' && nyc report --reporter=text-lcov > coverage1.lcov"
},

@@ -22,3 +22,5 @@ "repository": {

"dependencies": {
"util": "^0.12.5"
"async_hooks": "1.0.0",
"util": "0.12.5",
"uuid": "9.0.1"
},

@@ -25,0 +27,0 @@ "devDependencies": {

6

src/logger.d.ts

@@ -27,2 +27,5 @@ export declare const enum LogSeverity {

private static jsonTransformArgs;
private static handleJSONSpecialCharacter;
private static stringifyJSON;
private static generateLogSource;
verbose(formatter: unknown, ...args: Array<unknown>): void;

@@ -35,7 +38,6 @@ info(formatter: unknown, ...args: Array<unknown>): void;

constructor(loggerName: string, callbacks: Callback);
log(logSeverity: LogSeverity, extraData: Record<string, unknown>, formatter: unknown, ...args: Array<unknown>): void;
private transformArgs;
private isLogEnabled;
private log;
private static handleJSONSpecialCharacter;
}
export {};
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -31,3 +8,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const util_1 = __importDefault(require("util"));
const fs = __importStar(require("node:fs"));
const trace_1 = require("./trace");
exports.LogLevel = {

@@ -49,2 +26,3 @@ verbose: 1,

};
const currentFolder = __dirname;
function generateMatchAndDoesNotMatchArray(input = '') {

@@ -117,19 +95,63 @@ const positive = [];

}
static handleJSONSpecialCharacter(message) {
return message
.replace(/\\/g, '\\\\')
.replace(/\t/g, '\\t')
.replace(/"/g, '\\"')
.replace(/\r\n/g, '\\r\\n')
.replace(/\n/g, '\\n');
}
static stringifyJSON(json = {}) {
const jsonString = JSON.stringify(json);
if (jsonString === '{}') {
return '';
}
return jsonString;
}
static generateLogSource() {
const { stack } = new Error();
const logSource = stack.split('\n')
.find((line) => !line.includes(currentFolder)
&& line.trim().startsWith('at '));
if (!logSource) {
return '';
}
if (logSource[logSource.length - 1] === ')') {
const [caller, filePath] = logSource.split(' (');
const filePathSplit = filePath.substring(0, filePath.length - 1).split('/');
const [fileName, line, column] = filePathSplit.pop().split(':');
return JSON.stringify({
caller: caller.split('at ')[1],
fileName,
path: filePathSplit.join('/'),
line,
column,
});
}
const filePathSplit = logSource.split('at ')[1].split('/');
const [fileName, line, column] = filePathSplit.pop().split(':');
return JSON.stringify({
fileName,
path: filePathSplit.join('/'),
line,
column,
});
}
verbose(formatter, ...args) {
this.log("verbose" /* LogSeverity.VERBOSE */, formatter, ...args);
this.log("verbose" /* LogSeverity.VERBOSE */, {}, formatter, ...args);
}
info(formatter, ...args) {
this.log("info" /* LogSeverity.INFO */, formatter, ...args);
this.log("info" /* LogSeverity.INFO */, {}, formatter, ...args);
}
warn(formatter, ...args) {
this.log("warn" /* LogSeverity.WARN */, formatter, ...args);
this.log("warn" /* LogSeverity.WARN */, {}, formatter, ...args);
}
debug(formatter, ...args) {
this.log("debug" /* LogSeverity.DEBUG */, formatter, ...args);
this.log("debug" /* LogSeverity.DEBUG */, {}, formatter, ...args);
}
error(formatter, ...args) {
this.log("error" /* LogSeverity.ERROR */, formatter, ...args);
this.log("error" /* LogSeverity.ERROR */, {}, formatter, ...args);
}
fatal(formatter, ...args) {
this.log("fatal" /* LogSeverity.FATAL */, formatter, ...args);
this.log("fatal" /* LogSeverity.FATAL */, {}, formatter, ...args);
}

@@ -140,2 +162,15 @@ constructor(loggerName, callbacks) {

}
log(logSeverity, extraData, formatter, ...args) {
if (!this.isLogEnabled(logSeverity)) {
return;
}
if (this.callbacks.jsonLogging()) {
const source = Logger.generateLogSource();
const sessionInfoString = Logger.stringifyJSON(trace_1.Trace.getSessionInfo());
const extraDataString = Logger.stringifyJSON(extraData);
console.log(`{"className":"${this.name}","level":"${logSeverity}","message":"${Logger.jsonTransformArgs(formatter, ...args)}","stack":"${Logger.errorStack(formatter, ...args)}"${sessionInfoString ? `, "session": ${sessionInfoString}` : ''}${extraDataString ? `, "extraData": ${extraDataString}` : ''}${source ? `, "source": ${source}` : ''}}`);
return;
}
console.log(`${exports.DisplaySeverityMap[logSeverity]}:`, this.name, util_1.default.format(formatter, ...this.transformArgs(...args)));
}
transformArgs(...args) {

@@ -170,23 +205,4 @@ return args.map((each) => {

}
log(logSeverity, formatter, ...args) {
if (!this.isLogEnabled(logSeverity)) {
return;
}
if (this.callbacks.jsonLogging()) {
console.log(`{"className":"${this.name}","level":"${logSeverity}","message":"${Logger.jsonTransformArgs(formatter, ...args)}","stack":"${Logger.errorStack(formatter, ...args)}"}`);
fs.writeFileSync('./test.txt', `{"className":"${this.name}","level":"${logSeverity}","message":"${Logger.jsonTransformArgs(formatter, ...args)}","stack":"${Logger.errorStack(formatter, ...args)}"}`, 'utf-8');
return;
}
console.log(`${exports.DisplaySeverityMap[logSeverity]}:`, this.name, util_1.default.format(formatter, ...this.transformArgs(...args)));
}
static handleJSONSpecialCharacter(message) {
return message
.replace(/\\/g, '\\\\')
// .replace(/([^\\])"/g, '$1\\"')
.replace(/"/g, '\\"')
.replace(/\r\n/g, '\\r\\n')
.replace(/\n/g, '\\n');
}
}
exports.Logger = Logger;
//# sourceMappingURL=logger.js.map
import { Logger, LogSeverity } from './logger';
import { Trace } from './trace';
export declare class Logger4Node {
static Trace: typeof Trace;
private readonly _applicationName;

@@ -4,0 +6,0 @@ private stringLogging;

@@ -5,2 +5,3 @@ "use strict";

const logger_1 = require("./logger");
const trace_1 = require("./trace");
class Logger4Node {

@@ -35,2 +36,3 @@ static setLogLevel(logSeverity) {

exports.Logger4Node = Logger4Node;
Logger4Node.Trace = trace_1.Trace;
Logger4Node.setLogLevel(process.env.DEBUG_LEVEL);

@@ -37,0 +39,0 @@ Logger4Node.setLogPattern(process.env.DEBUG);

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