New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cf-nodejs-logging-support

Package Overview
Dependencies
Maintainers
4
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 1.1.2 to 2.0.0

.vscode/launch.json

129

cf-nodejs-logging-support-core/log-core.js

@@ -1,76 +0,86 @@

var winston = require("winston");
var util = require('util');
var os = require('os');
const nsPerSec = 1e9;
const logType = "log";
const loggingLevels = { 'error': 0, 'warn': 1, 'info': 2, 'verbose': 3, 'debug': 4, 'silly': 5 };
var initDummy = null;
var logLevelInt = 2;
var pattern = null;
var stdout = process.stdout;
// Customized transport, which specifies the correct logging format and logs to stdout
var consoleTransport = new(winston.transports.Console)({
timestamp: function () {
return Date.now();
},
level: "info",
formatter: function (options) {
// Return string will be passed to winston logger.
if (null !== pattern) {
if (undefined !== options.meta) {
var output = pattern;
for (var key in options.meta) {
if (typeof (options.meta[key]) === "object" && validObject(options.meta[key])) {
output = output.replace('{{' + key + '}}', JSON.stringify(options.meta[key]));
} else {
output = output.replace('{{' + key + '}}', options.meta[key]);
}
// Stringify and log given object to console. If a custom pattern is set, the referenced object fields are used to replace the references.
var writeLogToConsole = function(logObject) {
var output = "";
if (null != pattern) {
if (undefined !== logObject && logObject != null) {
output = pattern;
for (var key in logObject) {
if (typeof (logObject[key]) === "object" && validObject(logObject[key])) {
output = output.replace('{{' + key + '}}', JSON.stringify(logObject[key]));
} else {
output = output.replace('{{' + key + '}}', logObject[key]);
}
return output;
}
return "";
} else {
return (undefined !== options.meta && validObject(options.meta)) ? JSON.stringify(options.meta) : '';
}
} else {
output = (undefined !== logObject && validObject(logObject)) ? JSON.stringify(logObject) : '';
}
});
stdout.write(output + os.EOL);
}
var winstonLogger = new(winston.Logger)({
transports: [consoleTransport]
});
// Sets the minimum logging level. Messages with a lower level, will not be forwarded. (Levels: error, warn, info, verbose, debug, silly)
// Sets the minimum logging level. Messages with a lower level will not be forwarded. (Levels: error, warn, info, verbose, debug, silly)
var setLoggingLevel = function (level) {
consoleTransport.level = level;
};
logLevelInt = loggingLevels[level];
}
// Gets the minimum logging level. (Levels: error, warn, info, verbose, debug, silly)
var getLoggingLevel = function () {
return consoleTransport.level;
for(var key in loggingLevels) {
if(loggingLevels[key] == logLevelInt) {
return key;
}
}
};
// Initializes an empty log object
var initLog = function (logObject, time) {
var vcapEnvironment = ("VCAP_APPLICATION" in process.env) ? JSON.parse(process.env.VCAP_APPLICATION) : {};
var initLog = function () {
if (time == null) {
time = [0, 0];
var time = process.hrtime();
var logObject = {};
if (initDummy == null) {
logObject = prepareInitDummy();
initDummy = JSON.stringify(logObject);
} else {
logObject = JSON.parse(initDummy);
}
logObject.written_at = (new Date()).toJSON();
logObject.written_ts = time[0] * 1e9 + time[1];
logObject.written_ts = time[0] * nsPerSec + time[1];
logObject.component_type = "application";
logObject.component_id = !("application_id" in vcapEnvironment) ? "-" : vcapEnvironment.application_id;
logObject.component_name = !("application_name" in vcapEnvironment) ? "-" : vcapEnvironment.application_name;
logObject.component_instance = !("instance_index" in vcapEnvironment) ? "0" : vcapEnvironment.instance_index.toString();
logObject.layer = "[NODEJS]";
return logObject;
logObject.space_name = !("space_name" in vcapEnvironment) ? "-" : vcapEnvironment.space_name;
logObject.space_id = !("space_id" in vcapEnvironment) ? "-" : vcapEnvironment.space_id;
};
logObject.source_instance = logObject.component_instance;
var prepareInitDummy = function () {
var obj = {};
var vcapEnvironment = ("VCAP_APPLICATION" in process.env) ? JSON.parse(process.env.VCAP_APPLICATION) : {};
logObject.container_id = !("CF_INSTANCE_IP" in process.env) ? "-" : process.env.CF_INSTANCE_IP;
obj.component_type = "application";
obj.component_id = !("application_id" in vcapEnvironment) ? "-" : vcapEnvironment.application_id;
obj.component_name = !("application_name" in vcapEnvironment) ? "-" : vcapEnvironment.application_name;
obj.component_instance = !("instance_index" in vcapEnvironment) ? "0" : vcapEnvironment.instance_index.toString();
obj.source_instance = obj.component_instance;
logObject.logger = "nodejs-logger";
obj.layer = "[NODEJS]";
obj.space_name = !("space_name" in vcapEnvironment) ? "-" : vcapEnvironment.space_name;
obj.space_id = !("space_id" in vcapEnvironment) ? "-" : vcapEnvironment.space_id;
obj.container_id = !("CF_INSTANCE_IP" in process.env) ? "-" : process.env.CF_INSTANCE_IP;
obj.logger = "nodejs-logger";
return obj;
};

@@ -83,3 +93,7 @@

// Write log to console to be parsed by logstash
winstonLogger.log(level, '', logObject);
//winstonLogger.log(level, '', logObject);
if (logLevelInt >= loggingLevels[level]) {
writeLogToConsole(logObject);
}
};

@@ -111,2 +125,5 @@

var level = args[0];
if (logLevelInt < loggingLevels[level]) {
return false;
}
var customFields = null;

@@ -125,3 +142,3 @@

var logObject = {};
var logObject = initLog();

@@ -134,11 +151,12 @@ var req = this;

var time = process.hrtime();
initLog(logObject, time);
logObject.msg = msg;
logObject.type = "log";
logObject.type = logType;
if (customFields != null) {
for (var key in customFields) {
if(!((typeof customFields[key]) == "string")) {
customFields[key] = JSON.stringify(customFields[key]);
}
}
logObject.custom_fields = customFields;

@@ -148,2 +166,3 @@ }

sendLog(level, logObject);
return true;
};

@@ -150,0 +169,0 @@

@@ -17,7 +17,5 @@ // Log network activity for express applications

var logNetwork = function (req, res, next) {
var logObject = {};
var logSent = false;
var time = process.hrtime();
core.initLog(logObject, time);
var logObject = core.initLog();

@@ -24,0 +22,0 @@ //rendering the given arguments failsave against missing fields

@@ -17,7 +17,5 @@ // Log network activity for express applications

var logNetwork = function (req, res) {
var logObject = {};
var logSent = false;
var time = process.hrtime();
core.initLog(logObject, time);
var logObject = core.initLog();

@@ -24,0 +22,0 @@ //rendering the given arguments failsave against missing fields

@@ -19,6 +19,5 @@ /*jshint node:true */

var logNetwork = function (req, res, next) {
var logObject = {};
var time = process.hrtime();
var logSent = false;
core.initLog(logObject, time);
var logObject = core.initLog();

@@ -25,0 +24,0 @@ //rendering the given arguments failsave against missing fields

@@ -17,6 +17,3 @@ var winston = require("winston");

// Return string will be passed to winston logger.
var logObject = {};
var time = process.hrtime();
core.initLog(logObject, time);
var logObject = core.initLog();
if (options != null) {

@@ -23,0 +20,0 @@ if (options.level != null) {

{
"name": "cf-nodejs-logging-support",
"version": "1.1.2",
"description": "Logging tool for Cloud Foundry",
"keywords": [
"name": "cf-nodejs-logging-support",
"version": "2.0.0",
"description": "Logging tool for Cloud Foundry",
"keywords": [
"logging",

@@ -10,40 +10,42 @@ "cf",

],
"repository": {
"type": "git",
"url": "https://github.com/SAP/cf-nodejs-logging-support"
"repository": {
"type": "git",
"url": "https://github.com/SAP/cf-nodejs-logging-support"
},
"license": "Apache-2.0",
"author": {
"name": "Christian Dinse, Nicklas Dohrn"
},
"main": "./index.js",
"engines": {
"node": ">=4.0.0"
},
"dependencies": {
"request": "^2.81.0",
"uuid": "3.0.1"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "latest",
"istanbul": "^0.4.4",
"mocha": "^2.5.3",
"mock-require": "^1.3.0",
"node-mocks-http": "^1.6.4",
"rewire": "^2.5.2",
"sinon": "latest",
"winston": "^2.3.1"
},
"maintainers": [
{
"name": "nicklas dohrn",
"email": "nicklas.dohrn@sap.com"
},
"license": "Apache-2.0",
"author": {
"name": "Christian Dinse, Nicklas Dohrn"
},
"main": "./index.js",
"engines": {
"node": ">=4.0.0"
},
"dependencies": {
"uuid": "3.0.1",
"winston": "2.3.1"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "latest",
"istanbul": "^0.4.4",
"mocha": "^2.5.3",
"mock-require": "^1.3.0",
"rewire": "^2.5.2",
"sinon": "latest"
},
"maintainers": [
{
"name": "nicklas dohrn",
"email": "nicklas.dohrn@sap.com"
},
{
"name": "christian dinse",
"email": "christian.dinse@sap.com"
{
"name": "christian dinse",
"email": "christian.dinse@sap.com"
}
],
"scripts": {
"test": "istanbul cover node_modules/mocha/bin/_mocha"
}
"scripts": {
"test": "istanbul cover node_modules/mocha/bin/_mocha"
}
}

@@ -11,2 +11,4 @@ # Node.js Logging Support for Cloud Foundry

#### Version 2.0 introduced loging without Winston and changed custom fields to be parsed and reported as strings regardless of original type.
## Features

@@ -55,3 +57,3 @@

#### With restify:
```
```js
var restify = require('restify');

@@ -69,3 +71,3 @@ var log = require('cf-nodejs-logging-support');

#### With nodejs http:
```
```js
var log = require("cf-nodejs-logging-support");

@@ -117,3 +119,3 @@ const http = require('http');

With custom fields added to custom_fields field. Keep in mind, that the last argument is handled as custom fields object, if it is an object.
With custom fields added to custom_fields field. Keep in mind, that the last argument is handled as custom_fields object, if it is an object.
```js

@@ -132,3 +134,3 @@ logMessage("info", "Test data %j", {"field" :"value"});

### Winston Transport
This logging tool can be used in conjunction with Winston. Example:
This logging tool can be used in conjunction with Winston. Logging via Winston transport is limited to custom logs. Network activity can not be tracked automatically. Example:
```js

@@ -135,0 +137,0 @@ var express = require('express');

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