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

cf-nodejs-logging-support

Package Overview
Dependencies
Maintainers
0
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cf-nodejs-logging-support - npm Package Compare versions

Comparing version 7.4.0 to 7.5.0-beta.0

4

build/main/index.d.ts

@@ -5,3 +5,7 @@ import RootLogger from "./lib/logger/rootLogger";

export * from "./lib/config/interfaces";
export * from "./lib/logger/record";
export * from "./lib/logger/level";
export * from "./lib/logger/logger";
export * from "./lib/plugins/interfaces";
export * from "./lib/plugins/defaultOutput";
export * from "./lib/plugins/otelOutput";

@@ -26,4 +26,8 @@ "use strict";

__exportStar(require("./lib/config/interfaces"), exports);
__exportStar(require("./lib/logger/record"), exports);
__exportStar(require("./lib/logger/level"), exports);
__exportStar(require("./lib/logger/logger"), exports);
__exportStar(require("./lib/plugins/interfaces"), exports);
__exportStar(require("./lib/plugins/defaultOutput"), exports);
__exportStar(require("./lib/plugins/otelOutput"), exports);
//# sourceMappingURL=index.js.map

@@ -117,4 +117,7 @@ {

"enum": [
"errorMessage",
"errorName",
"level",
"message",
"rawStacktrace",
"requestReceivedAt",

@@ -121,0 +124,0 @@ "responseSentAt",

@@ -80,2 +80,5 @@ export interface ConfigObject {

Stacktrace = "stacktrace",
RawStacktrace = "rawStacktrace",
ErrorName = "errorName",
ErrorMessage = "errorMessage",
Level = "level"

@@ -82,0 +85,0 @@ }

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

DetailName["Stacktrace"] = "stacktrace";
DetailName["RawStacktrace"] = "rawStacktrace";
DetailName["ErrorName"] = "errorName";
DetailName["ErrorMessage"] = "errorMessage";
DetailName["Level"] = "level";

@@ -53,0 +56,0 @@ })(DetailName || (exports.DetailName = DetailName = {}));

@@ -11,1 +11,7 @@ export declare enum Level {

}
export declare class LevelUtils {
private static readonly defaultLevel;
static getLevel(level: String | Level): Level;
static getName(level: Level): string;
static isLevelEnabled(threshold: Level, level: Level): boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Level = void 0;
exports.LevelUtils = exports.Level = void 0;
var Level;

@@ -15,2 +15,27 @@ (function (Level) {

})(Level || (exports.Level = Level = {}));
class LevelUtils {
static getLevel(level) {
if (typeof level === 'string') {
const key = level.charAt(0).toUpperCase() + level.slice(1).toLowerCase();
const lvl = Level[key];
if (lvl !== undefined) {
return lvl;
}
}
else {
return level;
}
return LevelUtils.defaultLevel;
}
static getName(level) {
return Level[level].toLowerCase();
}
static isLevelEnabled(threshold, level) {
if (level <= Level.Off)
return false;
return level <= threshold;
}
}
exports.LevelUtils = LevelUtils;
LevelUtils.defaultLevel = Level.Info;
//# sourceMappingURL=level.js.map

1

build/main/lib/logger/logger.d.ts

@@ -9,3 +9,2 @@ import { Level } from './level';

private recordFactory;
private recordWriter;
protected loggingLevelThreshold: Level;

@@ -12,0 +11,0 @@ constructor(parent?: Logger, context?: Context);

@@ -7,8 +7,7 @@ "use strict";

exports.Logger = void 0;
const levelUtils_1 = __importDefault(require("../helper/levelUtils"));
const utils_1 = require("../middleware/utils");
const level_1 = require("./level");
const recordFactory_1 = __importDefault(require("./recordFactory"));
const recordWriter_1 = __importDefault(require("./recordWriter"));
const context_1 = __importDefault(require("./context"));
const pluginProvider_1 = __importDefault(require("../helper/pluginProvider"));
class Logger {

@@ -28,3 +27,2 @@ constructor(parent, context) {

this.recordFactory = recordFactory_1.default.getInstance();
this.recordWriter = recordWriter_1.default.getInstance();
}

@@ -41,8 +39,3 @@ createLogger(customFields, createNewContext) {

setLoggingLevel(level) {
if (typeof level === 'string') {
this.loggingLevelThreshold = levelUtils_1.default.getLevel(level);
}
else {
this.loggingLevelThreshold = level;
}
this.loggingLevelThreshold = level_1.LevelUtils.getLevel(level);
}

@@ -53,3 +46,3 @@ getLoggingLevel() {

}
return levelUtils_1.default.getName(this.loggingLevelThreshold);
return level_1.LevelUtils.getName(this.loggingLevelThreshold);
}

@@ -60,8 +53,3 @@ isLoggingLevel(level) {

}
if (typeof level === 'string') {
return levelUtils_1.default.isLevelEnabled(this.loggingLevelThreshold, levelUtils_1.default.getLevel(level));
}
else {
return levelUtils_1.default.isLevelEnabled(this.loggingLevelThreshold, level);
}
return level_1.LevelUtils.isLevelEnabled(this.loggingLevelThreshold, level_1.LevelUtils.getLevel(level));
}

@@ -72,11 +60,4 @@ logMessage(level, ...args) {

const loggerCustomFields = this.getCustomFieldsFromLogger(this);
let levelName;
if (typeof level === 'string') {
levelName = level;
}
else {
levelName = levelUtils_1.default.getName(level);
}
const record = this.recordFactory.buildMsgRecord(this.registeredCustomFields, loggerCustomFields, levelName, args, this.context);
this.recordWriter.writeLog(record);
const record = this.recordFactory.buildMsgRecord(this.registeredCustomFields, loggerCustomFields, level_1.LevelUtils.getLevel(level), args, this.context);
pluginProvider_1.default.getInstance().getOutputPlugins().forEach(output => { output.writeRecord(record); });
}

@@ -83,0 +64,0 @@ error(...args) {

@@ -1,5 +0,24 @@

export default class Record {
payload: any;
metadata: any;
constructor(level: string);
import { Level } from "./level";
export declare class Record {
payload: {
[key: string]: any;
};
metadata: RecordMetadata;
constructor(type: RecordType, level: Level);
}
export declare class RecordMetadata {
type: RecordType;
level: Level;
message?: string;
rawStacktrace?: string;
stacktrace?: string[];
errorName?: string;
errorMessage?: string;
customFieldNames: string[];
constructor(type: RecordType, level: Level);
}
export type RecordFieldValue = string | string[] | number | boolean;
export declare enum RecordType {
Request = 0,
Message = 1
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecordType = exports.RecordMetadata = exports.Record = void 0;
class Record {
constructor(level) {
constructor(type, level) {
this.payload = {};
this.metadata = {
level: level
};
this.metadata = new RecordMetadata(type, level);
}
}
exports.default = Record;
exports.Record = Record;
class RecordMetadata {
constructor(type, level) {
this.type = type;
this.level = level;
this.customFieldNames = new Array();
}
}
exports.RecordMetadata = RecordMetadata;
var RecordType;
(function (RecordType) {
RecordType[RecordType["Request"] = 0] = "Request";
RecordType[RecordType["Message"] = 1] = "Message";
})(RecordType || (exports.RecordType = RecordType = {}));
//# sourceMappingURL=record.js.map

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

import Record from './record';
import { Record } from './record';
import Context from './context';
import { Level } from './level';
export default class RecordFactory {

@@ -11,4 +12,4 @@ private static instance;

static getInstance(): RecordFactory;
buildMsgRecord(registeredCustomFields: Array<string>, loggerCustomFields: Map<string, any>, levelName: string, args: Array<any>, context?: Context): Record;
buildReqRecord(levelName: string, req: any, res: any, context: Context): Record;
buildMsgRecord(registeredCustomFields: Array<string>, loggerCustomFields: Map<string, any>, level: Level, args: Array<any>, context?: Context): Record;
buildReqRecord(level: Level, req: any, res: any, context: Context): Record;
private addCustomFields;

@@ -15,0 +16,0 @@ private addContext;

@@ -13,3 +13,3 @@ "use strict";

const cache_1 = __importDefault(require("./cache"));
const record_1 = __importDefault(require("./record"));
const record_1 = require("./record");
const sourceUtils_1 = __importDefault(require("./sourceUtils"));

@@ -30,9 +30,12 @@ class RecordFactory {

// init a new record and assign fields with output "msg-log"
buildMsgRecord(registeredCustomFields, loggerCustomFields, levelName, args, context) {
buildMsgRecord(registeredCustomFields, loggerCustomFields, level, args, context) {
const lastArg = args[args.length - 1];
let customFieldsFromArgs = new Map();
let record = new record_1.default(levelName);
let record = new record_1.Record(record_1.RecordType.Message, level);
if (typeof lastArg === "object") {
if (this.stacktraceUtils.isErrorWithStacktrace(lastArg)) {
record.metadata.stacktrace = this.stacktraceUtils.prepareStacktrace(lastArg.stack);
record.metadata.rawStacktrace = lastArg.stack;
record.metadata.errorMessage = lastArg.message;
record.metadata.errorName = lastArg.name;
}

@@ -42,2 +45,5 @@ else if ((0, utils_1.isValidObject)(lastArg)) {

record.metadata.stacktrace = this.stacktraceUtils.prepareStacktrace(lastArg._error.stack);
record.metadata.rawStacktrace = lastArg._error.stack;
record.metadata.errorMessage = lastArg._error.message;
record.metadata.errorName = lastArg._error.name;
delete lastArg._error;

@@ -68,4 +74,4 @@ }

// init a new record and assign fields with output "req-log"
buildReqRecord(levelName, req, res, context) {
let record = new record_1.default(levelName);
buildReqRecord(level, req, res, context) {
let record = new record_1.Record(record_1.RecordType.Request, level);
// assign static fields from cache

@@ -113,2 +119,3 @@ const cacheFields = this.config.getCacheReqFields();

}
record.metadata.customFieldNames.push(key);
});

@@ -115,0 +122,0 @@ // Write custom fields in the correct order and correlates i to the place in registeredCustomFields

@@ -5,5 +5,7 @@ /// <reference types="node" />

import { ConfigObject, CustomFieldsFormat, CustomFieldsTypeConversion, Framework } from '../config/interfaces';
import { OutputPlugin } from '../plugins/interfaces';
import { Logger } from './logger';
export default class RootLogger extends Logger {
private static instance;
private defaultOutput;
private config;

@@ -20,2 +22,5 @@ private constructor();

setSinkFunction(func: (level: string, payload: string) => any): void;
addOutputPlugin(outputPlugin: OutputPlugin): void;
setOutputPlugins(...outputPlugin: OutputPlugin[]): void;
getOutputPlugins(): OutputPlugin[];
enableTracing(input: string | string[]): void;

@@ -22,0 +27,0 @@ logNetwork(req: any, res: any, next: any): void;

@@ -12,6 +12,7 @@ "use strict";

const responseAccessor_1 = __importDefault(require("../middleware/responseAccessor"));
const defaultOutput_1 = require("../plugins/defaultOutput");
const pluginProvider_1 = __importDefault(require("../helper/pluginProvider"));
const winstonTransport_1 = __importDefault(require("../winston/winstonTransport"));
const level_1 = require("./level");
const logger_1 = require("./logger");
const recordWriter_1 = __importDefault(require("./recordWriter"));
class RootLogger extends logger_1.Logger {

@@ -22,2 +23,4 @@ constructor() {

this.loggingLevelThreshold = level_1.Level.Info;
this.defaultOutput = new defaultOutput_1.DefaultOutput();
pluginProvider_1.default.getInstance().setOutputPlugins([this.defaultOutput]);
}

@@ -52,4 +55,13 @@ static getInstance() {

setSinkFunction(func) {
recordWriter_1.default.getInstance().setSinkFunction(func);
this.defaultOutput.setSinkFunction(func);
}
addOutputPlugin(outputPlugin) {
pluginProvider_1.default.getInstance().addOutputPlugin(outputPlugin);
}
setOutputPlugins(...outputPlugin) {
pluginProvider_1.default.getInstance().setOutputPlugins(outputPlugin);
}
getOutputPlugins() {
return pluginProvider_1.default.getInstance().getOutputPlugins();
}
enableTracing(input) {

@@ -56,0 +68,0 @@ return this.config.enableTracing(input);

import { ConfigField, Output } from '../config/interfaces';
import Record from './record';
import { Record, RecordFieldValue } from './record';
export default class SourceUtils {

@@ -11,3 +11,3 @@ private static instance;

static getInstance(): SourceUtils;
getValue(field: ConfigField, record: Record, output: Output, req?: any, res?: any): string | number | boolean | undefined;
getValue(field: ConfigField, record: Record, output: Output, req?: any, res?: any): RecordFieldValue | undefined;
private getValueFromSource;

@@ -14,0 +14,0 @@ private getDetail;

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

const responseAccessor_1 = __importDefault(require("../middleware/responseAccessor"));
const level_1 = require("../logger/level");
const NS_PER_MS = 1e6;

@@ -139,4 +140,13 @@ const REDACTED_PLACEHOLDER = "redacted";

break;
case interfaces_1.DetailName.RawStacktrace:
value = record.metadata.rawStacktrace;
break;
case interfaces_1.DetailName.ErrorMessage:
value = record.metadata.errorMessage;
break;
case interfaces_1.DetailName.ErrorName:
value = record.metadata.errorName;
break;
case interfaces_1.DetailName.Level:
value = record.metadata.level;
value = level_1.LevelUtils.getName(record.metadata.level);
break;

@@ -184,2 +194,3 @@ }

}
return 0;
}

@@ -195,2 +206,3 @@ parseFloatValue(value) {

}
return 0;
}

@@ -197,0 +209,0 @@ parseBooleanValue(value) {

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

const jwtService_1 = __importDefault(require("../helper/jwtService"));
const levelUtils_1 = __importDefault(require("../helper/levelUtils"));
const level_1 = require("../logger/level");
const logger_1 = require("../logger/logger");
const recordFactory_1 = __importDefault(require("../logger/recordFactory"));
const recordWriter_1 = __importDefault(require("../logger/recordWriter"));
const context_1 = __importDefault(require("../logger/context"));

@@ -17,2 +16,3 @@ const rootLogger_1 = __importDefault(require("../logger/rootLogger"));

const responseAccessor_1 = __importDefault(require("./responseAccessor"));
const pluginProvider_1 = __importDefault(require("../helper/pluginProvider"));
class Middleware {

@@ -41,7 +41,7 @@ static logNetwork(req, res, next) {

const levelName = config_1.default.getInstance().getReqLoggingLevel();
const level = levelUtils_1.default.getLevel(levelName);
const threshold = levelUtils_1.default.getLevel(req.logger.getLoggingLevel());
if (levelUtils_1.default.isLevelEnabled(threshold, level)) {
const record = recordFactory_1.default.getInstance().buildReqRecord(levelName, req, res, context);
recordWriter_1.default.getInstance().writeLog(record);
const level = level_1.LevelUtils.getLevel(levelName);
const threshold = level_1.LevelUtils.getLevel(req.logger.getLoggingLevel());
if (level_1.LevelUtils.isLevelEnabled(threshold, level)) {
const record = recordFactory_1.default.getInstance().buildReqRecord(level, req, res, context);
pluginProvider_1.default.getInstance().getOutputPlugins().forEach(output => { output.writeRecord(record); });
}

@@ -48,0 +48,0 @@ logSent = true;

{
"name": "cf-nodejs-logging-support",
"version": "7.4.0",
"version": "7.5.0-beta.0",
"description": "Logging tool for Cloud Foundry",

@@ -64,2 +64,3 @@ "keywords": [

"dependencies": {
"@opentelemetry/api-logs": "^0.51.0",
"ajv": "^8.11.0",

@@ -66,0 +67,0 @@ "json-stringify-safe": "^5.0.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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