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
6
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.0.0-beta.1 to 7.0.0-beta.2

2

build/main/lib/config/config-validator.js

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

exports.default = ConfigValidator;
ConfigValidator.ajv = new ajv_1.default();
ConfigValidator.ajv = new ajv_1.default({ strict: false });
//# sourceMappingURL=config-validator.js.map

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

updateCache(output, cacheFields, req, res) {
const writtenAt = new Date();
let cache = {};

@@ -48,3 +47,3 @@ if (output == "msg-log") {

cacheFields.forEach(field => {
cache[field.name] = this.sourceUtils.getValue(field, cache, output, writtenAt, req, res);
cache[field.name] = this.sourceUtils.getValue(field, cache, output, 0, req, res);
});

@@ -51,0 +50,0 @@ }

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

setProperties(req) {
const writtenAt = new Date();
const contextFields = this.config.getContextFields();
contextFields.forEach(field => {
this.properties[field.name] = this.sourceUtils.getValue(field, this.properties, "context", writtenAt, req);
this.properties[field.name] = this.sourceUtils.getValue(field, this.properties, "context", 0, req);
});

@@ -31,0 +30,0 @@ }

@@ -12,3 +12,3 @@ import ReqContext from "./context";

buildMsgRecord(registeredCustomFields: Array<string>, loggerCustomFields: Map<string, any>, level: string, args: Array<any>, context?: ReqContext): any;
buildReqRecord(req: any, res: any, context: ReqContext): any;
buildReqRecord(req: any, res: any, context: ReqContext, reqReceivedAt: number): any;
private addCustomFields;

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

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

// assign dynamic fields
record = this.addDynamicFields(record, "msg-log");
record = this.addDynamicFields(record, "msg-log", 0);
// read and copy values from context

@@ -62,3 +62,3 @@ if (context) {

// init a new record and assign fields with output "req-log"
buildReqRecord(req, res, context) {
buildReqRecord(req, res, context, reqReceivedAt) {
const reqLoggingLevel = this.config.getReqLoggingLevel();

@@ -71,3 +71,3 @@ let record = { "level": reqLoggingLevel };

// assign dynamic fields
record = this.addDynamicFields(record, "req-log", req, res);
record = this.addDynamicFields(record, "req-log", reqReceivedAt, req, res);
record = this.addContext(record, context);

@@ -131,4 +131,3 @@ const loggerCustomFields = Object.assign({}, req.logger.extractCustomFieldsFromLogger(req.logger));

}
addDynamicFields(record, output, req, res) {
const writtenAt = new Date();
addDynamicFields(record, output, reqReceivedAt, req, res) {
// assign dynamic fields

@@ -142,3 +141,3 @@ const fields = (output == "msg-log") ? this.config.noCacheMsgFields : this.config.noCacheReqFields;

}
record[field.name] = this.sourceUtils.getValue(field, record, output, writtenAt, req, res);
record[field.name] = this.sourceUtils.getValue(field, record, output, reqReceivedAt, req, res);
});

@@ -145,0 +144,0 @@ return record;

@@ -13,3 +13,3 @@ import { ConfigField, Source } from "../config/interfaces";

isCacheable(source: Source | Source[]): boolean;
getValue(field: ConfigField, record: any, origin: origin, writtenAt: Date, req?: any, res?: any): string | number | boolean | undefined;
getValue(field: ConfigField, record: any, origin: origin, reqReceivedAt: number, req?: any, res?: any): string | number | boolean | undefined;
private getFieldValue;

@@ -16,0 +16,0 @@ private getReqFieldValue;

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

const response_accessor_1 = __importDefault(require("../middleware/response-accessor"));
const stringifySafe = require('json-stringify-safe');
const { v4: uuid } = require('uuid');

@@ -52,3 +51,3 @@ const NS_PER_MS = 1e6;

}
getValue(field, record, origin, writtenAt, req, res) {
getValue(field, record, origin, reqReceivedAt, req, res) {
let value;

@@ -58,9 +57,9 @@ if (!Array.isArray(field.source)) {

case "msg-log":
value = this.getFieldValue(field.source, record, writtenAt);
value = this.getFieldValue(field.source, record, reqReceivedAt);
break;
case "req-log":
value = this.getReqFieldValue(field.source, record, writtenAt, req, res);
value = this.getReqFieldValue(field.source, record, reqReceivedAt, req, res);
break;
case "context":
value = this.getContextFieldValue(field.source, record, req);
value = this.getContextFieldValue(field.source, record, reqReceivedAt, req);
break;

@@ -70,3 +69,3 @@ }

else {
value = this.getValueFromSources(field, record, origin, writtenAt, req, res);
value = this.getValueFromSources(field, record, origin, reqReceivedAt, req, res);
}

@@ -81,9 +80,5 @@ // Handle default

}
// Stringify, if necessary.
if ((typeof value) != "string") {
value = stringifySafe(value);
}
return value;
}
getFieldValue(source, record, writtenAt) {
getFieldValue(source, record, reqReceivedAt) {
let value;

@@ -101,11 +96,11 @@ switch (source.type) {

case "meta":
if (writtenAt == null) {
if (reqReceivedAt == null) {
return;
}
if (source.fieldName == "request_received_at") {
value = record["written_at"];
value = new Date(reqReceivedAt).toJSON();
break;
}
if (source.fieldName == "response_time_ms") {
value = (Date.now() - writtenAt.getTime());
value = (Date.now() - reqReceivedAt);
break;

@@ -118,3 +113,3 @@ }

if (source.fieldName == "written_at") {
value = writtenAt.toJSON();
value = new Date().toJSON();
break;

@@ -124,6 +119,6 @@ }

var lower = process.hrtime()[1] % NS_PER_MS;
var higher = writtenAt.getTime() * NS_PER_MS;
var higher = reqReceivedAt * NS_PER_MS;
let written_ts = higher + lower;
//This reorders written_ts, if the new timestamp seems to be smaller
// due to different rollover times for process.hrtime and writtenAt.getTime
// due to different rollover times for process.hrtime and reqReceivedAt.getTime
if (written_ts < this.lastTimestamp) {

@@ -145,3 +140,3 @@ written_ts += NS_PER_MS;

}
getReqFieldValue(source, record, writtenAt, req, res) {
getReqFieldValue(source, record, reqReceivedAt, req, res) {
if (req == null || res == null) {

@@ -165,3 +160,3 @@ throw new Error("Please pass req and res as argument to get value for req-log field.");

default:
value = this.getFieldValue(source, record, writtenAt);
value = this.getFieldValue(source, record, reqReceivedAt);
}

@@ -174,3 +169,3 @@ if (source.regExp && value) {

// if source is request, then assign to context. If not, then ignore.
getContextFieldValue(source, record, req) {
getContextFieldValue(source, record, reqReceivedAt, req) {
if (req == null) {

@@ -188,4 +183,3 @@ throw new Error("Please pass req as argument to get value for req-log field.");

case "config-field":
const writtenAt = new Date();
value = this.getFieldValue(source, record, writtenAt);
value = this.getFieldValue(source, record, reqReceivedAt);
break;

@@ -202,3 +196,3 @@ case "uuid":

// iterate through sources until one source returns a value
getValueFromSources(field, record, origin, writtenAt, req, res) {
getValueFromSources(field, record, origin, reqReceivedAt, req, res) {
if (origin == "req-log" && (req == null || res == null)) {

@@ -219,5 +213,5 @@ throw new Error("Please pass req and res as argument to get value for req-log field.");

let source = field.source[sourceIndex];
fieldValue = origin == "msg-log" ? this.getFieldValue(source, record, writtenAt) :
origin == "req-log" ? this.getReqFieldValue(source, record, writtenAt, req, res) :
this.getContextFieldValue(source, record, req);
fieldValue = origin == "msg-log" ? this.getFieldValue(source, record, reqReceivedAt) :
origin == "req-log" ? this.getReqFieldValue(source, record, reqReceivedAt, req, res) :
this.getContextFieldValue(source, record, reqReceivedAt, req);
if (source.regExp && fieldValue) {

@@ -224,0 +218,0 @@ fieldValue = this.validateRegExp(fieldValue, source.regExp);

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

static logNetwork(req, res, next) {
const reqReceivedAt = Date.now();
let logSent = false;

@@ -34,3 +35,3 @@ const context = new context_1.default(req);

if (!logSent) {
const record = record_factory_1.default.getInstance().buildReqRecord(req, res, context);
const record = record_factory_1.default.getInstance().buildReqRecord(req, res, context, reqReceivedAt);
const reqLoggingLevel = level_utils_1.default.getLevel(record.level);

@@ -37,0 +38,0 @@ const loggingLevelThreshold = level_utils_1.default.getLevel(req.logger.getLoggingLevel());

{
"name": "cf-nodejs-logging-support",
"version": "7.0.0-beta.1",
"version": "7.0.0-beta.2",
"description": "Logging tool for Cloud Foundry",

@@ -42,8 +42,12 @@ "keywords": [

"chai": "^4.3.6",
"connect": "^3.7.0",
"eslint": "^8.27.0",
"eslint-plugin-functional": "^4.4.1",
"eslint-plugin-import": "^2.26.0",
"express": "^4.18.2",
"http": "^0.0.1-security",
"import-fresh": "^3.3.0",
"mocha": "^9.2.2",
"node-mocks-http": "^1.11.0",
"restify": "^9.0.0",
"rewire": "^6.0.0",

@@ -66,4 +70,5 @@ "supertest": "^6.2.2",

"jsonwebtoken": "^8.5.1",
"uuid": "^9.0.0",
"winston-transport": "^4.5.0"
}
}

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