cf-nodejs-logging-support
Advanced tools
Comparing version 7.0.0-beta.2 to 7.0.0-beta.3
@@ -1,3 +0,3 @@ | ||
import RootLogger from "./lib/logger/root-logger"; | ||
import RootLogger from "./lib/logger/rootLogger"; | ||
declare const rootLogger: RootLogger; | ||
export = rootLogger; |
@@ -5,5 +5,5 @@ "use strict"; | ||
}; | ||
const root_logger_1 = __importDefault(require("./lib/logger/root-logger")); | ||
const rootLogger = root_logger_1.default.getInstance(); | ||
const rootLogger_1 = __importDefault(require("./lib/logger/rootLogger")); | ||
const rootLogger = rootLogger_1.default.getInstance(); | ||
module.exports = rootLogger; | ||
//# sourceMappingURL=index.js.map |
@@ -1,5 +0,6 @@ | ||
import { ConfigField, ConfigObject, customFieldsFormat, framework } from './interfaces'; | ||
import { ConfigField, ConfigObject, CustomFieldsFormat, Framework } from './interfaces'; | ||
export default class Config { | ||
private static instance; | ||
private config; | ||
private validator; | ||
private envVarHelper; | ||
private msgFields; | ||
@@ -10,2 +11,3 @@ private reqFields; | ||
noCacheReqFields: ConfigField[]; | ||
private config; | ||
private constructor(); | ||
@@ -19,8 +21,8 @@ static getInstance(): Config; | ||
getCacheReqFields(): ConfigField[]; | ||
getFramework(): framework; | ||
getReqLoggingLevel(): string | undefined; | ||
getFramework(): Framework; | ||
getReqLoggingLevel(): string; | ||
addConfig(configs: ConfigObject[]): void; | ||
setCustomFieldsFormat(format: customFieldsFormat): void; | ||
setCustomFieldsFormat(format: CustomFieldsFormat): void; | ||
setStartupMessageEnabled(enabled: boolean): void; | ||
setFramework(framework: framework): void; | ||
setFramework(framework: Framework): void; | ||
setRequestLogLevel(name: string): void; | ||
@@ -32,2 +34,3 @@ enableTracing(input: string[]): void; | ||
private addToList; | ||
private isCacheable; | ||
} |
@@ -6,5 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const env_service_1 = __importDefault(require("../core/env-service")); | ||
const envService_1 = __importDefault(require("../helper/envService")); | ||
const envVarHelper_1 = __importDefault(require("../helper/envVarHelper")); | ||
const cache_1 = __importDefault(require("../logger/cache")); | ||
const source_utils_1 = require("../logger/source-utils"); | ||
const configValidator_1 = __importDefault(require("./configValidator")); | ||
const config_cf_json_1 = __importDefault(require("./default/config-cf.json")); | ||
@@ -15,17 +16,18 @@ const config_core_json_1 = __importDefault(require("./default/config-core.json")); | ||
const config_sap_passport_json_1 = __importDefault(require("./default/config-sap-passport.json")); | ||
const config_validator_1 = __importDefault(require("./config-validator")); | ||
const utils_1 = require("./utils"); | ||
const interfaces_1 = require("./interfaces"); | ||
class Config { | ||
constructor() { | ||
this.msgFields = []; | ||
this.reqFields = []; | ||
this.contextFields = []; | ||
this.config = { | ||
"fields": [], | ||
"settableFields": [], | ||
"customFieldsFormat": "cloud-logging", | ||
"customFieldsFormat": interfaces_1.CustomFieldsFormat.default, | ||
"reqLoggingLevel": "info", | ||
"outputStartupMsg": false, | ||
"framework": "express" | ||
"framework": interfaces_1.Framework.express | ||
}; | ||
this.msgFields = []; | ||
this.reqFields = []; | ||
this.contextFields = []; | ||
this.validator = new configValidator_1.default(); | ||
this.envVarHelper = envVarHelper_1.default.getInstance(); | ||
this.noCacheMsgFields = []; | ||
@@ -36,2 +38,3 @@ this.noCacheReqFields = []; | ||
if (!Config.instance) { | ||
Config.instance = new Config(); | ||
const configFiles = [ | ||
@@ -41,4 +44,5 @@ config_core_json_1.default, | ||
]; | ||
const env = env_service_1.default.getRuntimeName(); | ||
const boundServices = env_service_1.default.getBoundServices(); | ||
const envService = envService_1.default.getInstance(); | ||
const env = envService.getRuntimeName(); | ||
const boundServices = envService.getBoundServices(); | ||
if (env == "Kyma") { | ||
@@ -50,13 +54,10 @@ configFiles.push(config_kyma_json_1.default); | ||
} | ||
Config.instance = new Config(); | ||
if (boundServices["application-logs"] && boundServices["cloud-logging"]) { | ||
Config.instance.setCustomFieldsFormat("all"); | ||
Config.instance.setCustomFieldsFormat(interfaces_1.CustomFieldsFormat.all); | ||
} | ||
else if (boundServices["application-logs"]) { | ||
Config.instance.setCustomFieldsFormat("application-logging"); | ||
// configFiles.push(appLoggingConfig as ConfigObject); | ||
Config.instance.setCustomFieldsFormat(interfaces_1.CustomFieldsFormat.applicationLogging); | ||
} | ||
else { | ||
Config.instance.setCustomFieldsFormat("cloud-logging"); | ||
// configFiles.push(cloudLoggingConfig as ConfigObject); | ||
Config.instance.setCustomFieldsFormat(interfaces_1.CustomFieldsFormat.cloudLogging); | ||
} | ||
@@ -113,3 +114,4 @@ Config.instance.addConfig(configFiles); | ||
getReqLoggingLevel() { | ||
return Config.instance.config.reqLoggingLevel; | ||
let level = Config.instance.config.reqLoggingLevel; | ||
return level ? level : "info"; | ||
} | ||
@@ -119,3 +121,3 @@ addConfig(configs) { | ||
var _a; | ||
const validation = config_validator_1.default.isValid(file); | ||
const validation = this.validator.isValid(file); | ||
if (validation != true) { | ||
@@ -138,6 +140,7 @@ const error = JSON.stringify(validation[1]); | ||
if (field.envVarSwitch) { | ||
field._meta.isEnabled = (0, utils_1.isEnvVarEnabled)(field.envVarSwitch); | ||
field._meta.isEnabled = this.envVarHelper.isVarEnabled(field.envVarSwitch); | ||
} | ||
if (field.envVarRedact) { | ||
field._meta.isRedacted = !(0, utils_1.isEnvVarEnabled)(field.envVarRedact); // if the env var is actually set to true, we do not redact => invert result | ||
// if the env var is actually set to true, we do not redact => invert result | ||
field._meta.isRedacted = !this.envVarHelper.isVarEnabled(field.envVarRedact); | ||
} | ||
@@ -148,9 +151,9 @@ if (field.disable) { | ||
// check if cache field | ||
if (source_utils_1.SourceUtils.getInstance().isCacheable(field.source)) { | ||
if (this.isCacheable(field.source)) { | ||
field._meta.isCache = true; | ||
} | ||
if ((_a = field.output) === null || _a === void 0 ? void 0 : _a.includes('msg-log')) { | ||
if ((_a = field.output) === null || _a === void 0 ? void 0 : _a.includes(interfaces_1.Output.msgLog)) { | ||
this.addToList(this.msgFields, field); | ||
} | ||
if ((_b = field.output) === null || _b === void 0 ? void 0 : _b.includes('req-log')) { | ||
if ((_b = field.output) === null || _b === void 0 ? void 0 : _b.includes(interfaces_1.Output.reqLog)) { | ||
this.addToList(this.reqFields, field); | ||
@@ -164,6 +167,6 @@ } | ||
if (field._meta.isCache == false) { | ||
if ((_c = field.output) === null || _c === void 0 ? void 0 : _c.includes("msg-log")) { | ||
if ((_c = field.output) === null || _c === void 0 ? void 0 : _c.includes(interfaces_1.Output.msgLog)) { | ||
this.addToList(this.noCacheMsgFields, field); | ||
} | ||
if ((_d = field.output) === null || _d === void 0 ? void 0 : _d.includes("req-log")) { | ||
if ((_d = field.output) === null || _d === void 0 ? void 0 : _d.includes(interfaces_1.Output.reqLog)) { | ||
this.addToList(this.noCacheReqFields, field); | ||
@@ -196,3 +199,3 @@ } | ||
const cache = cache_1.default.getInstance(); | ||
cache.markCacheDirty(); | ||
cache.markDirty(); | ||
} | ||
@@ -212,3 +215,3 @@ setCustomFieldsFormat(format) { | ||
enableTracing(input) { | ||
for (var i in input) { | ||
for (let i in input) { | ||
switch (i.toLowerCase()) { | ||
@@ -236,3 +239,3 @@ case "sap_passport": | ||
const cache = cache_1.default.getInstance(); | ||
cache.markCacheDirty(); | ||
cache.markDirty(); | ||
} | ||
@@ -253,4 +256,32 @@ // get index of field in config | ||
} | ||
isCacheable(s) { | ||
let sources = Array.isArray(s) ? s : [s]; | ||
for (let i in sources) { | ||
let source = sources[i]; | ||
switch (source.type) { | ||
case interfaces_1.SourceType.static: | ||
return true; | ||
case interfaces_1.SourceType.env: | ||
// if this is the last source it does not matter, if the env var exists | ||
if (i == (sources.length - 1).toString()) | ||
return true; | ||
// otherwise we have to check if there is a value to be sure that the field can be cached. | ||
let value; | ||
if (source.path) { | ||
value = envVarHelper_1.default.getInstance().resolveNestedVar(source.path); | ||
} | ||
else { | ||
value = process.env[source.varName]; | ||
} | ||
if (value != null) | ||
return true; | ||
break; | ||
default: | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
exports.default = Config; | ||
//# sourceMappingURL=config.js.map |
{ | ||
"outputStartupMsg": true, | ||
"framework": "express", | ||
"fields": [ | ||
@@ -15,6 +17,56 @@ { | ||
{ | ||
"name": "type", | ||
"source": [ | ||
{ | ||
"type": "static", | ||
"value": "request", | ||
"output": "req-log" | ||
}, | ||
{ | ||
"type": "static", | ||
"value": "log", | ||
"output": "msg-log" | ||
} | ||
], | ||
"output": [ | ||
"req-log", | ||
"msg-log" | ||
] | ||
}, | ||
{ | ||
"name": "msg", | ||
"source": { | ||
"type": "meta", | ||
"fieldName": "message" | ||
}, | ||
"output": [ | ||
"msg-log" | ||
] | ||
}, | ||
{ | ||
"name": "level", | ||
"source": { | ||
"type": "meta", | ||
"fieldName": "level" | ||
}, | ||
"output": [ | ||
"msg-log", | ||
"req-log" | ||
] | ||
}, | ||
{ | ||
"name": "stacktrace", | ||
"source": { | ||
"type": "meta", | ||
"fieldName": "stacktrace" | ||
}, | ||
"output": [ | ||
"msg-log" | ||
] | ||
}, | ||
{ | ||
"name": "written_at", | ||
"source": { | ||
"type": "meta", | ||
"fieldName": "written_at" | ||
"fieldName": "writtenAt" | ||
}, | ||
@@ -30,3 +82,3 @@ "output": [ | ||
"type": "meta", | ||
"fieldName": "written_ts" | ||
"fieldName": "writtenTs" | ||
}, | ||
@@ -38,5 +90,3 @@ "output": [ | ||
} | ||
], | ||
"outputStartupMsg": true, | ||
"framework": "express" | ||
] | ||
} |
{ | ||
"reqLoggingLevel": "info", | ||
"fields": [ | ||
@@ -26,12 +27,2 @@ { | ||
{ | ||
"name": "type", | ||
"source": { | ||
"type": "static", | ||
"value": "request" | ||
}, | ||
"output": [ | ||
"req-log" | ||
] | ||
}, | ||
{ | ||
"name": "request", | ||
@@ -133,3 +124,3 @@ "source": { | ||
"source": { | ||
"type": "config-field", | ||
"type": "req-object", | ||
"fieldName": "remote_host" | ||
@@ -154,4 +145,4 @@ }, | ||
"source": { | ||
"type": "config-field", | ||
"fieldName": "written_at" | ||
"type": "meta", | ||
"fieldName": "requestReceivedAt" | ||
}, | ||
@@ -166,3 +157,3 @@ "output": [ | ||
"type": "meta", | ||
"fieldName": "response_time_ms" | ||
"fieldName": "responseTimeMs" | ||
}, | ||
@@ -177,3 +168,3 @@ "output": [ | ||
"type": "meta", | ||
"fieldName": "response_sent_at" | ||
"fieldName": "responseSentAt" | ||
}, | ||
@@ -371,4 +362,3 @@ "output": [ | ||
} | ||
], | ||
"reqLoggingLevel": "info" | ||
] | ||
} |
@@ -35,7 +35,3 @@ { | ||
"items": { | ||
"enum": [ | ||
"msg-log", | ||
"req-log" | ||
], | ||
"type": "string" | ||
"$ref": "#/definitions/Output" | ||
}, | ||
@@ -92,2 +88,28 @@ "type": "array" | ||
}, | ||
"CustomFieldsFormat": { | ||
"enum": [ | ||
"all", | ||
"application-logging", | ||
"cloud-logging", | ||
"default", | ||
"disabled" | ||
], | ||
"type": "string" | ||
}, | ||
"Framework": { | ||
"enum": [ | ||
"connect", | ||
"express", | ||
"nodejs-http", | ||
"restify" | ||
], | ||
"type": "string" | ||
}, | ||
"Output": { | ||
"enum": [ | ||
"msg-log", | ||
"req-log" | ||
], | ||
"type": "string" | ||
}, | ||
"Source": { | ||
@@ -100,4 +122,7 @@ "additionalProperties": false, | ||
"framework": { | ||
"$ref": "#/definitions/framework" | ||
"$ref": "#/definitions/Framework" | ||
}, | ||
"output": { | ||
"$ref": "#/definitions/Output" | ||
}, | ||
"path": { | ||
@@ -113,3 +138,3 @@ "items": { | ||
"type": { | ||
"$ref": "#/definitions/sources" | ||
"$ref": "#/definitions/SourceType" | ||
}, | ||
@@ -128,23 +153,4 @@ "value": { | ||
}, | ||
"customFieldsFormat": { | ||
"SourceType": { | ||
"enum": [ | ||
"all", | ||
"application-logging", | ||
"cloud-logging", | ||
"default", | ||
"disabled" | ||
], | ||
"type": "string" | ||
}, | ||
"framework": { | ||
"enum": [ | ||
"connect", | ||
"express", | ||
"nodejs-http", | ||
"restify" | ||
], | ||
"type": "string" | ||
}, | ||
"sources": { | ||
"enum": [ | ||
"config-field", | ||
@@ -165,3 +171,3 @@ "env", | ||
"customFieldsFormat": { | ||
"$ref": "#/definitions/customFieldsFormat" | ||
"$ref": "#/definitions/CustomFieldsFormat" | ||
}, | ||
@@ -175,3 +181,3 @@ "fields": { | ||
"framework": { | ||
"$ref": "#/definitions/framework" | ||
"$ref": "#/definitions/Framework" | ||
}, | ||
@@ -178,0 +184,0 @@ "outputStartupMsg": { |
export interface ConfigObject { | ||
fields?: ConfigField[]; | ||
settableFields?: string[]; | ||
customFieldsFormat?: customFieldsFormat; | ||
customFieldsFormat?: CustomFieldsFormat; | ||
outputStartupMsg?: boolean; | ||
reqLoggingLevel?: string; | ||
framework?: framework; | ||
framework?: Framework; | ||
} | ||
@@ -14,3 +14,3 @@ export interface ConfigField { | ||
source: Source | Source[]; | ||
output: outputs[]; | ||
output: Output[]; | ||
disable?: boolean; | ||
@@ -23,3 +23,3 @@ default?: string | number | boolean; | ||
export interface Source { | ||
type: sources; | ||
type: SourceType; | ||
value?: string; | ||
@@ -29,6 +29,7 @@ path?: string[]; | ||
varName?: string; | ||
framework?: framework; | ||
regExp?: string; | ||
framework?: Framework; | ||
output?: Output; | ||
} | ||
interface ConfigFieldMeta { | ||
export interface ConfigFieldMeta { | ||
isRedacted: boolean; | ||
@@ -39,6 +40,29 @@ isEnabled: boolean; | ||
} | ||
declare type sources = "static" | "env" | "config-field" | "req-header" | "res-header" | "req-object" | "res-object" | "meta" | "uuid"; | ||
export declare type outputs = "msg-log" | "req-log"; | ||
export declare type framework = "express" | "restify" | "connect" | "nodejs-http"; | ||
export declare type customFieldsFormat = "application-logging" | "cloud-logging" | "all" | "disabled" | "default"; | ||
export {}; | ||
export declare enum Framework { | ||
express = "express", | ||
restify = "restify", | ||
connect = "connect", | ||
nodejsHttp = "nodejs-http" | ||
} | ||
export declare enum Output { | ||
msgLog = "msg-log", | ||
reqLog = "req-log" | ||
} | ||
export declare enum CustomFieldsFormat { | ||
applicationLogging = "application-logging", | ||
cloudLogging = "cloud-logging", | ||
all = "all", | ||
disabled = "disabled", | ||
default = "default" | ||
} | ||
export declare enum SourceType { | ||
static = "static", | ||
env = "env", | ||
configField = "config-field", | ||
reqHeader = "req-header", | ||
resHeader = "res-header", | ||
reqObject = "req-object", | ||
resObject = "res-object", | ||
meta = "meta", | ||
uuid = "uuid" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SourceType = exports.CustomFieldsFormat = exports.Output = exports.Framework = void 0; | ||
var Framework; | ||
(function (Framework) { | ||
Framework["express"] = "express"; | ||
Framework["restify"] = "restify"; | ||
Framework["connect"] = "connect"; | ||
Framework["nodejsHttp"] = "nodejs-http"; | ||
})(Framework = exports.Framework || (exports.Framework = {})); | ||
var Output; | ||
(function (Output) { | ||
Output["msgLog"] = "msg-log"; | ||
Output["reqLog"] = "req-log"; | ||
})(Output = exports.Output || (exports.Output = {})); | ||
var CustomFieldsFormat; | ||
(function (CustomFieldsFormat) { | ||
CustomFieldsFormat["applicationLogging"] = "application-logging"; | ||
CustomFieldsFormat["cloudLogging"] = "cloud-logging"; | ||
CustomFieldsFormat["all"] = "all"; | ||
CustomFieldsFormat["disabled"] = "disabled"; | ||
CustomFieldsFormat["default"] = "default"; | ||
})(CustomFieldsFormat = exports.CustomFieldsFormat || (exports.CustomFieldsFormat = {})); | ||
var SourceType; | ||
(function (SourceType) { | ||
SourceType["static"] = "static"; | ||
SourceType["env"] = "env"; | ||
SourceType["configField"] = "config-field"; | ||
SourceType["reqHeader"] = "req-header"; | ||
SourceType["resHeader"] = "res-header"; | ||
SourceType["reqObject"] = "req-object"; | ||
SourceType["resObject"] = "res-object"; | ||
SourceType["meta"] = "meta"; | ||
SourceType["uuid"] = "uuid"; | ||
})(SourceType = exports.SourceType || (exports.SourceType = {})); | ||
//# sourceMappingURL=interfaces.js.map |
@@ -1,2 +0,2 @@ | ||
import { ConfigField } from "../config/interfaces"; | ||
import { ConfigField } from '../config/interfaces'; | ||
export default class Cache { | ||
@@ -13,4 +13,4 @@ private static instance; | ||
getCacheReqRecord(cacheFields: ConfigField[], req: any, res: any): any; | ||
markCacheDirty(): void; | ||
markDirty(): void; | ||
private updateCache; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const source_utils_1 = require("./source-utils"); | ||
const interfaces_1 = require("../config/interfaces"); | ||
const sourceUtils_1 = __importDefault(require("./sourceUtils")); | ||
class Cache { | ||
constructor() { | ||
this.sourceUtils = source_utils_1.SourceUtils.getInstance(); | ||
this.sourceUtils = sourceUtils_1.default.getInstance(); | ||
this.shouldUpdateMsg = true; | ||
@@ -18,3 +22,3 @@ this.shouldUpdateReq = true; | ||
if (this.shouldUpdateMsg) { | ||
this.updateCache("msg-log", cacheFields); | ||
this.updateCache(interfaces_1.Output.msgLog, cacheFields); | ||
this.shouldUpdateMsg = false; | ||
@@ -26,3 +30,3 @@ } | ||
if (this.shouldUpdateReq) { | ||
this.updateCache("req-log", cacheFields, req, res); | ||
this.updateCache(interfaces_1.Output.reqLog, cacheFields, req, res); | ||
this.shouldUpdateReq = false; | ||
@@ -32,3 +36,3 @@ } | ||
} | ||
markCacheDirty() { | ||
markDirty() { | ||
this.shouldUpdateMsg = true; | ||
@@ -39,3 +43,3 @@ this.shouldUpdateReq = true; | ||
let cache = {}; | ||
if (output == "msg-log") { | ||
if (output == interfaces_1.Output.msgLog) { | ||
this.cacheMsgRecord = {}; | ||
@@ -50,3 +54,3 @@ cache = this.cacheMsgRecord; | ||
cacheFields.forEach(field => { | ||
cache[field.name] = this.sourceUtils.getValue(field, cache, output, 0, req, res); | ||
cache[field.name] = this.sourceUtils.getValue(field, cache, output, req, res); | ||
}); | ||
@@ -53,0 +57,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import Level from "./level"; | ||
import ReqContext from "./context"; | ||
import Level from './level'; | ||
import RequestContext from './requestContext'; | ||
export default class Logger { | ||
@@ -11,3 +11,3 @@ private parent?; | ||
protected loggingLevelThreshold: Level; | ||
constructor(parent?: Logger, reqContext?: ReqContext); | ||
constructor(parent?: Logger, reqContext?: RequestContext); | ||
createLogger(customFields?: any): Logger; | ||
@@ -39,3 +39,3 @@ setLoggingLevel(name: string): void; | ||
setTenantSubdomain(value: string): void; | ||
private extractCustomFieldsFromLogger; | ||
private getCustomFieldsFromLogger; | ||
} |
@@ -6,7 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const levelUtils_1 = __importDefault(require("../helper/levelUtils")); | ||
const utils_1 = require("../middleware/utils"); | ||
const level_1 = __importDefault(require("./level")); | ||
const level_utils_1 = __importDefault(require("./level-utils")); | ||
const record_writer_1 = __importDefault(require("./record-writer")); | ||
const record_factory_1 = __importDefault(require("./record-factory")); | ||
const utils_1 = require("../middleware/utils"); | ||
const recordFactory_1 = __importDefault(require("./recordFactory")); | ||
const recordWriter_1 = __importDefault(require("./recordWriter")); | ||
class Logger { | ||
@@ -25,4 +25,4 @@ constructor(parent, reqContext) { | ||
} | ||
this.recordFactory = record_factory_1.default.getInstance(); | ||
this.recordWriter = record_writer_1.default.getInstance(); | ||
this.recordFactory = recordFactory_1.default.getInstance(); | ||
this.recordWriter = recordWriter_1.default.getInstance(); | ||
} | ||
@@ -38,3 +38,3 @@ createLogger(customFields) { | ||
setLoggingLevel(name) { | ||
this.loggingLevelThreshold = level_utils_1.default.getLevel(name); | ||
this.loggingLevelThreshold = levelUtils_1.default.getLevel(name); | ||
} | ||
@@ -45,3 +45,3 @@ getLoggingLevel() { | ||
} | ||
return level_utils_1.default.getName(this.loggingLevelThreshold); | ||
return levelUtils_1.default.getName(this.loggingLevelThreshold); | ||
} | ||
@@ -52,4 +52,4 @@ isLoggingLevel(name) { | ||
} | ||
const level = level_utils_1.default.getLevel(name); | ||
return level_utils_1.default.isLevelEnabled(this.loggingLevelThreshold, level); | ||
const level = levelUtils_1.default.getLevel(name); | ||
return levelUtils_1.default.isLevelEnabled(this.loggingLevelThreshold, level); | ||
} | ||
@@ -59,3 +59,3 @@ logMessage(levelName, ..._args) { | ||
return; | ||
const loggerCustomFields = Object.assign({}, this.extractCustomFieldsFromLogger(this)); | ||
const loggerCustomFields = Object.assign({}, this.getCustomFieldsFromLogger(this)); | ||
const record = this.recordFactory.buildMsgRecord(this.registeredCustomFields, loggerCustomFields, levelName, _args, this.context); | ||
@@ -117,28 +117,28 @@ this.recordWriter.writeLog(record); | ||
var _a; | ||
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.getProp("correlation_id"); | ||
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.getProperty("correlation_id"); | ||
} | ||
setCorrelationId(value) { | ||
var _a; | ||
(_a = this.context) === null || _a === void 0 ? void 0 : _a.setProp("correlation_id", value); | ||
(_a = this.context) === null || _a === void 0 ? void 0 : _a.setProperty("correlation_id", value); | ||
} | ||
getTenantId() { | ||
var _a; | ||
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.getProp("tenant_id"); | ||
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.getProperty("tenant_id"); | ||
} | ||
setTenantId(value) { | ||
var _a; | ||
(_a = this.context) === null || _a === void 0 ? void 0 : _a.setProp("tenant_id", value); | ||
(_a = this.context) === null || _a === void 0 ? void 0 : _a.setProperty("tenant_id", value); | ||
} | ||
getTenantSubdomain() { | ||
var _a; | ||
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.getProp("tenant_subdomain"); | ||
return (_a = this.context) === null || _a === void 0 ? void 0 : _a.getProperty("tenant_subdomain"); | ||
} | ||
setTenantSubdomain(value) { | ||
var _a; | ||
(_a = this.context) === null || _a === void 0 ? void 0 : _a.setProp("tenant_subdomain", value); | ||
(_a = this.context) === null || _a === void 0 ? void 0 : _a.setProperty("tenant_subdomain", value); | ||
} | ||
extractCustomFieldsFromLogger(logger) { | ||
getCustomFieldsFromLogger(logger) { | ||
let fields = {}; | ||
if (logger.parent && logger.parent !== this) { | ||
fields = this.extractCustomFieldsFromLogger(logger.parent); | ||
fields = this.getCustomFieldsFromLogger(logger.parent); | ||
} | ||
@@ -145,0 +145,0 @@ if ((0, utils_1.isValidObject)(logger.customFields)) { |
@@ -6,23 +6,24 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const level_utils_1 = __importDefault(require("../logger/level-utils")); | ||
const record_factory_1 = __importDefault(require("../logger/record-factory")); | ||
const root_logger_1 = __importDefault(require("../logger/root-logger")); | ||
const jwt_service_1 = require("../config/jwt-service"); | ||
const request_Accessor_1 = __importDefault(require("./request-Accessor")); | ||
const record_writer_1 = __importDefault(require("../logger/record-writer")); | ||
const context_1 = __importDefault(require("../logger/context")); | ||
const jwtService_1 = __importDefault(require("../helper/jwtService")); | ||
const levelUtils_1 = __importDefault(require("../helper/levelUtils")); | ||
const logger_1 = __importDefault(require("../logger/logger")); | ||
const recordFactory_1 = __importDefault(require("../logger/recordFactory")); | ||
const recordWriter_1 = __importDefault(require("../logger/recordWriter")); | ||
const requestContext_1 = __importDefault(require("../logger/requestContext")); | ||
const rootLogger_1 = __importDefault(require("../logger/rootLogger")); | ||
const requestAccessor_1 = __importDefault(require("./requestAccessor")); | ||
const config_1 = __importDefault(require("../config/config")); | ||
class Middleware { | ||
static logNetwork(req, res, next) { | ||
let logSent = false; | ||
const context = new requestContext_1.default(req); | ||
const parentLogger = rootLogger_1.default.getInstance(); | ||
const reqReceivedAt = Date.now(); | ||
let logSent = false; | ||
const context = new context_1.default(req); | ||
const parent = root_logger_1.default.getInstance(); | ||
// initialize Logger with parent to set registered fields | ||
let networkLogger = new logger_1.default(parent, context); | ||
let jwtService = jwt_service_1.JWTService.getInstance(); | ||
var dynLogLevelHeader = jwtService.getDynLogLevelHeaderName(); | ||
var token = request_Accessor_1.default.getInstance().getHeaderField(req, dynLogLevelHeader); | ||
const networkLogger = new logger_1.default(parentLogger, context); | ||
const jwtService = jwtService_1.default.getInstance(); | ||
const dynLogLevelHeader = jwtService.getDynLogLevelHeaderName(); | ||
const token = requestAccessor_1.default.getInstance().getHeaderField(req, dynLogLevelHeader); | ||
if (token) { | ||
let dynLevel = jwtService.getDynLogLevel(token); | ||
const dynLevel = jwtService.getDynLogLevel(token); | ||
if (dynLevel != null) { | ||
@@ -33,9 +34,12 @@ networkLogger.setLoggingLevel(dynLevel); | ||
req.logger = networkLogger; | ||
req._receivedAt = reqReceivedAt; | ||
const finishLog = () => { | ||
if (!logSent) { | ||
const record = record_factory_1.default.getInstance().buildReqRecord(req, res, context, reqReceivedAt); | ||
const reqLoggingLevel = level_utils_1.default.getLevel(record.level); | ||
const loggingLevelThreshold = level_utils_1.default.getLevel(req.logger.getLoggingLevel()); | ||
if (level_utils_1.default.isLevelEnabled(loggingLevelThreshold, reqLoggingLevel)) { | ||
record_writer_1.default.getInstance().writeLog(record); | ||
res._sentAt = Date.now(); | ||
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); | ||
} | ||
@@ -42,0 +46,0 @@ logSent = true; |
@@ -1,3 +0,3 @@ | ||
import { IFrameworkService } from "./interfaces"; | ||
import { IFrameworkService } from './interfaces'; | ||
export declare function assignFrameworkService(): IFrameworkService; | ||
export declare function isValidObject(obj: any, canBeEmpty?: any): boolean; | ||
export declare function isValidObject(obj: any, canBeEmpty?: boolean): boolean; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const config_1 = __importDefault(require("../config/config")); | ||
const interfaces_1 = require("../config/interfaces"); | ||
const connect_1 = __importDefault(require("./framework-services/connect")); | ||
@@ -16,8 +17,9 @@ const express_1 = __importDefault(require("./framework-services/express")); | ||
switch (framework) { | ||
case "restify": | ||
case interfaces_1.Framework.restify: | ||
return new restify_1.default(); | ||
case "nodejs-http": | ||
case interfaces_1.Framework.nodejsHttp: | ||
return new plainhttp_1.default(); | ||
case "connect": | ||
case interfaces_1.Framework.connect: | ||
return new connect_1.default(); | ||
case interfaces_1.Framework.express: | ||
default: | ||
@@ -24,0 +26,0 @@ return new express_1.default(); |
{ | ||
"name": "cf-nodejs-logging-support", | ||
"version": "7.0.0-beta.2", | ||
"version": "7.0.0-beta.3", | ||
"description": "Logging tool for Cloud Foundry", | ||
"keywords": [ | ||
"logging", | ||
"cf", | ||
"perfx" | ||
"cloud-foundry" | ||
], | ||
@@ -25,16 +24,15 @@ "main": "build/main/index.js", | ||
"build": "npm run build-json-schema && tsc -p tsconfig.json", | ||
"start": "npm run build-json-schema && tsc -p tsconfig.json && node build/main/index.js", | ||
"fix:lint": "eslint src --ext .ts --fix", | ||
"test": "npm run start && mocha 'src/test/**/*.test.js'", | ||
"test:lint": "eslint src --ext .ts", | ||
"test-performance": "mocha 'src/performance-test/*.test.js'", | ||
"test": "npm run build-json-schema && tsc -p tsconfig.json && node build/main/index.js && ./node_modules/mocha/bin/mocha 'src/test/**/*.test.js'", | ||
"test-lint": "eslint src --ext .ts", | ||
"test-performance": "./node_modules/mocha/bin/mocha 'src/performance-test/*.test.js'", | ||
"build-json-schema": "typescript-json-schema 'src/lib/config/interfaces.ts' ConfigObject --noExtraProps --required --out 'src/lib/config/default/config-schema.json'" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14.14" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.13", | ||
"@types/json-stringify-safe": "^5.0.0", | ||
"@types/node": "^17.0.45", | ||
"@types/restify": "^8.5.4", | ||
"@types/triple-beam": "^1.3.2", | ||
"@types/uuid": "^9.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.42.1", | ||
@@ -45,6 +43,5 @@ "@typescript-eslint/parser": "^5.42.1", | ||
"eslint": "^8.27.0", | ||
"eslint-plugin-functional": "^4.4.1", | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"express": "^4.18.2", | ||
"http": "^0.0.1-security", | ||
"import-fresh": "^3.3.0", | ||
@@ -56,6 +53,5 @@ "mocha": "^9.2.2", | ||
"supertest": "^6.2.2", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.23.21", | ||
"triple-beam": "^1.3.0", | ||
"typescript": "^4.8.4", | ||
"typescript-json-schema": "^0.53.0" | ||
"typescript-json-schema": "^0.55.0" | ||
}, | ||
@@ -71,3 +67,3 @@ "files": [ | ||
"json-stringify-safe": "^5.0.1", | ||
"jsonwebtoken": "^8.5.1", | ||
"jsonwebtoken": "^9.0.0", | ||
"uuid": "^9.0.0", | ||
@@ -74,0 +70,0 @@ "winston-transport": "^4.5.0" |
@@ -5,3 +5,3 @@ # Node.js Logging Support for Cloud Foundry | ||
[](https://www.npmjs.com/package/cf-nodejs-logging-support) | ||
[](https://travis-ci.com/SAP/cf-nodejs-logging-support) | ||
[](https://github.com/SAP/cf-nodejs-logging-support/actions/workflows/node.js.yml) | ||
[](https://api.reuse.software/info/github.com/SAP/cf-nodejs-logging-support) | ||
@@ -8,0 +8,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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
21
193880
98
2895
1
+ Addedjsonwebtoken@9.0.2(transitive)
+ Addedsemver@7.7.1(transitive)
- Removedjsonwebtoken@8.5.1(transitive)
- Removedsemver@5.7.2(transitive)
Updatedjsonwebtoken@^9.0.0