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-beta.4 to 7.4.0

build/main/lib/helper/levelUtils.d.ts

4

build/main/index.d.ts

@@ -5,7 +5,3 @@ 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,8 +26,4 @@ "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

@@ -1,2 +0,2 @@

import { ConfigField, ConfigObject, CustomFieldsFormat, Framework } from './interfaces';
import { ConfigField, ConfigObject, CustomFieldsFormat, CustomFieldsTypeConversion, Framework } from './interfaces';
export default class Config {

@@ -24,2 +24,3 @@ private static instance;

setCustomFieldsFormat(format: CustomFieldsFormat): void;
setCustomFieldsTypeConversion(conversion: CustomFieldsTypeConversion): void;
setStartupMessageEnabled(enabled: boolean): void;

@@ -26,0 +27,0 @@ setFramework(framework: Framework): void;

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

}
Config.instance.setCustomFieldsTypeConversion(interfaces_1.CustomFieldsTypeConversion.Stringify);
Config.instance.addConfig(configFiles);

@@ -178,2 +179,5 @@ }

}
if (file.customFieldsTypeConversion) {
Config.instance.config.customFieldsTypeConversion = file.customFieldsTypeConversion;
}
if (file.framework) {

@@ -194,2 +198,5 @@ Config.instance.config.framework = file.framework;

}
setCustomFieldsTypeConversion(conversion) {
Config.instance.config.customFieldsTypeConversion = conversion;
}
setStartupMessageEnabled(enabled) {

@@ -196,0 +203,0 @@ Config.instance.config.outputStartupMsg = enabled;

@@ -108,9 +108,13 @@ {

},
"CustomFieldsTypeConversion": {
"enum": [
"retain",
"stringify"
],
"type": "string"
},
"DetailName": {
"enum": [
"errorMessage",
"errorName",
"level",
"message",
"rawStacktrace",
"requestReceivedAt",

@@ -200,2 +204,5 @@ "responseSentAt",

},
"customFieldsTypeConversion": {
"$ref": "#/definitions/CustomFieldsTypeConversion"
},
"fields": {

@@ -202,0 +209,0 @@ "items": {

export interface ConfigObject {
fields?: ConfigField[];
customFieldsFormat?: CustomFieldsFormat;
customFieldsTypeConversion?: CustomFieldsTypeConversion;
outputStartupMsg?: boolean;

@@ -56,2 +57,6 @@ reqLoggingLevel?: string;

}
export declare enum CustomFieldsTypeConversion {
Retain = "retain",
Stringify = "stringify"
}
export declare enum SourceType {

@@ -76,5 +81,2 @@ Static = "static",

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

@@ -81,0 +83,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Conversion = exports.DetailName = exports.SourceType = exports.CustomFieldsFormat = exports.Output = exports.Framework = void 0;
exports.Conversion = exports.DetailName = exports.SourceType = exports.CustomFieldsTypeConversion = exports.CustomFieldsFormat = exports.Output = exports.Framework = void 0;
var Framework;

@@ -25,2 +25,7 @@ (function (Framework) {

})(CustomFieldsFormat || (exports.CustomFieldsFormat = CustomFieldsFormat = {}));
var CustomFieldsTypeConversion;
(function (CustomFieldsTypeConversion) {
CustomFieldsTypeConversion["Retain"] = "retain";
CustomFieldsTypeConversion["Stringify"] = "stringify";
})(CustomFieldsTypeConversion || (exports.CustomFieldsTypeConversion = CustomFieldsTypeConversion = {}));
var SourceType;

@@ -47,5 +52,2 @@ (function (SourceType) {

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

@@ -52,0 +54,0 @@ })(DetailName || (exports.DetailName = DetailName = {}));

@@ -11,7 +11,1 @@ 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.LevelUtils = exports.Level = void 0;
exports.Level = void 0;
var Level;

@@ -15,27 +15,2 @@ (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

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

private recordFactory;
private recordWriter;
protected loggingLevelThreshold: Level;

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

@@ -7,7 +7,8 @@ "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 {

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

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

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

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

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

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

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

}
return level_1.LevelUtils.isLevelEnabled(this.loggingLevelThreshold, level_1.LevelUtils.getLevel(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);
}
}

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

const loggerCustomFields = this.getCustomFieldsFromLogger(this);
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); });
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);
}

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

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

import { Level } from "./level";
export declare class Record {
payload: {
[key: string]: any;
};
metadata: RecordMetadata;
constructor(type: RecordType, level: Level);
export default class Record {
payload: any;
metadata: any;
constructor(level: string);
}
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(type, level) {
constructor(level) {
this.payload = {};
this.metadata = new RecordMetadata(type, level);
this.metadata = {
level: level
};
}
}
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 = {}));
exports.default = Record;
//# sourceMappingURL=record.js.map

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

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

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

static getInstance(): RecordFactory;
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;
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;
private addCustomFields;

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

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

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

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

// init a new record and assign fields with output "msg-log"
buildMsgRecord(registeredCustomFields, loggerCustomFields, level, args, context) {
buildMsgRecord(registeredCustomFields, loggerCustomFields, levelName, args, context) {
const lastArg = args[args.length - 1];
let customFieldsFromArgs = new Map();
let record = new record_1.Record(record_1.RecordType.Message, level);
let record = new record_1.default(levelName);
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;
}

@@ -45,5 +42,2 @@ 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;

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

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

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

const customFieldsFormat = this.config.getConfig().customFieldsFormat;
const customFieldsTypeConversion = this.config.getConfig().customFieldsTypeConversion;
// if format "disabled", do not log any custom fields

@@ -100,16 +95,23 @@ if (customFieldsFormat == interfaces_1.CustomFieldsFormat.Disabled) {

providedFields.forEach((value, key) => {
// Stringify, if necessary.
if ((typeof value) != "string") {
value = (0, json_stringify_safe_1.default)(value);
}
if ([interfaces_1.CustomFieldsFormat.CloudLogging, interfaces_1.CustomFieldsFormat.All, interfaces_1.CustomFieldsFormat.Default].includes(customFieldsFormat)
|| record.payload[key] != null || this.config.isSettable(key)) {
record.payload[key] = value;
// Stringify, if conversion type 'stringify' is selected and value is not a string already.
if (customFieldsTypeConversion == interfaces_1.CustomFieldsTypeConversion.Stringify && (typeof value) != "string") {
record.payload[key] = (0, json_stringify_safe_1.default)(value);
}
else {
record.payload[key] = value;
}
}
if ([interfaces_1.CustomFieldsFormat.ApplicationLogging, interfaces_1.CustomFieldsFormat.All].includes(customFieldsFormat)) {
indexedCustomFields[key] = value;
// Stringify, if necessary.
if ((typeof value) != "string") {
indexedCustomFields[key] = (0, json_stringify_safe_1.default)(value);
}
else {
indexedCustomFields[key] = value;
}
}
record.metadata.customFieldNames.push(key);
});
//writes custom fields in the correct order and correlates i to the place in registeredCustomFields
// Write custom fields in the correct order and correlates i to the place in registeredCustomFields
if (Object.keys(indexedCustomFields).length > 0) {

@@ -116,0 +118,0 @@ let res = {};

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

@@ -18,7 +16,5 @@ private constructor();

setCustomFieldsFormat(format: CustomFieldsFormat): void;
setCustomFieldsTypeConversion(conversion: CustomFieldsTypeConversion): void;
setStartupMessageEnabled(enabled: boolean): void;
setSinkFunction(func: (level: string, payload: string) => any): void;
addOutputPlugin(outputPlugin: OutputPlugin): void;
setOutputPlugins(...outputPlugin: OutputPlugin[]): void;
getOutputPlugins(): OutputPlugin[];
enableTracing(input: string | string[]): void;

@@ -25,0 +21,0 @@ logNetwork(req: any, res: any, next: any): void;

@@ -12,7 +12,6 @@ "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 {

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

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

@@ -48,2 +45,5 @@ static getInstance() {

}
setCustomFieldsTypeConversion(conversion) {
return this.config.setCustomFieldsTypeConversion(conversion);
}
setStartupMessageEnabled(enabled) {

@@ -53,13 +53,4 @@ return this.config.setStartupMessageEnabled(enabled);

setSinkFunction(func) {
this.defaultOutput.setSinkFunction(func);
recordWriter_1.default.getInstance().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) {

@@ -66,0 +57,0 @@ return this.config.enableTracing(input);

import { ConfigField, Output } from '../config/interfaces';
import { Record, RecordFieldValue } from './record';
import Record 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): RecordFieldValue | undefined;
getValue(field: ConfigField, record: Record, output: Output, req?: any, res?: any): string | number | boolean | undefined;
private getValueFromSource;

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

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

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

@@ -140,13 +139,4 @@ 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 = level_1.LevelUtils.getName(record.metadata.level);
value = record.metadata.level;
break;

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

}
return 0;
}

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

}
return 0;
}

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

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

const jwtService_1 = __importDefault(require("../helper/jwtService"));
const level_1 = require("../logger/level");
const levelUtils_1 = __importDefault(require("../helper/levelUtils"));
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"));

@@ -16,3 +17,2 @@ 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 = 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); });
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);
}

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

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

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

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

@@ -67,0 +66,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

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