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
5
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 6.4.3 to 6.5.0

.reuse/dep5

86

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

@@ -47,6 +47,11 @@ const util = require("util");

var boundServices;
var convenientLogFunctions = [];
var convenientLevelFunctions = [];
var defaultCustomEnabled = true;
var cfCustomEnabled = false;
// Initializes the core logger, including setup of environment var defined settings

@@ -83,4 +88,25 @@ var init = function () {

}
//Reading bindings from context
var boundServices = JSONparseSave(process.env.VCAP_SERVICES);
if(boundServices["application-logs"]) {
cfCustomEnabled = true;
defaultCustomEnabled = false;
}
if(boundServices["cloud-logs"]) {
defaultCustomEnabled = true;
}
};
var JSONparseSave = function (value) {
var tmp = {};
if(value)
try {
tmp = JSON.parse(value);
} catch (e) {
tmp = {};
}
return tmp;
}
var setConfig = function (config) {

@@ -143,2 +169,6 @@ precompileConfig(config);

var getBoundServices = function () {
return boundServices;
}
// Assigns default values to empty fields, if defined, OR adds a reference to a configured fallback

@@ -568,8 +598,7 @@ // method otherwise.

var customFields = {};
var value;
for (var key in providedFields) {
// Skip unregistered fields
value = providedFields[key];
var value = providedFields[key];
// Write value to customFields object. Stringify, if necessary.
// Stringify, if necessary.
if ((typeof value) != "string") {

@@ -579,7 +608,7 @@ value = stringifySafe(value);

if (registeredCustomFields.includes(key)) {
if(defaultCustomEnabled)
logObject[key] = value;
if (cfCustomEnabled)
customFields[key] = value;
} else if (logObject[key] == null && key != "custom_fields") {
logObject[key] = value;
}
}

@@ -589,5 +618,6 @@

if (Object.keys(customFields).length > 0) {
res = {};
var res = {};
res.string = [];
counter = 0;
var key;
for(var i = 0; i < registeredCustomFields.length; i++) {

@@ -725,2 +755,36 @@ key = registeredCustomFields[i]

//Sets the custom field format by hand. Returns true on correct strings.
var overrideCustomFieldFormat = function(value) {
if(typeof value == "string") {
switch (value) {
case "application-logging":
defaultCustomEnabled = false;
cfCustomEnabled = true;
break;
case "all":
defaultCustomEnabled = true;
cfCustomEnabled = true;
break;
case "disabled":
defaultCustomEnabled = false;
cfCustomEnabled = false;
break;
case "default":
case "cloud-logging":
defaultCustomEnabled = true;
cfCustomEnabled = false;
break;
default:
defaultCustomEnabled = true;
cfCustomEnabled = false;
return false;
}
return true;
} else {
defaultCustomEnabled = true;
cfCustomEnabled = false;
return false;
}
}
// Get the name of the dynamic log level header

@@ -795,2 +859,4 @@ var getDynLogLevelHeaderName = function () {

exports.setSinkFunction = setSinkFunction;
exports.overrideField = overrideField;
exports.overrideField = overrideField;
exports.overrideCustomFieldFormat = overrideCustomFieldFormat;
exports.getBoundServices = getBoundServices;

@@ -22,2 +22,6 @@ //loading core logger functionality

exports.getBoundServices = function() {
return coreLogger.getBoundServices();
}
// Sets the given function as log sink. Following arguments will be passed to the sink function: level, output

@@ -84,4 +88,9 @@ exports.setSinkFunction = function (func) {

};
exports.overrideNetworkField = function (field, value) {
return coreLogger.overrideField(field, value);
};
exports.overrideCustomFieldFormat = function (value) {
return coreLogger.overrideCustomFieldFormat(value);
};

2

package.json
{
"name": "cf-nodejs-logging-support",
"version": "6.4.3",
"version": "6.5.0",
"description": "Logging tool for Cloud Foundry",

@@ -5,0 +5,0 @@ "keywords": [

# Node.js Logging Support for Cloud Foundry
[![Version npm](https://img.shields.io/npm/v/cf-nodejs-logging-support.svg?style=flat-square)](https://www.npmjs.com/package/cf-nodejs-logging-support)[![npm Downloads](https://img.shields.io/npm/dm/cf-nodejs-logging-support.svg?style=flat-square)](https://www.npmjs.com/package/cf-nodejs-logging-support)[![Build Status](https://img.shields.io/travis/SAP/cf-nodejs-logging-support/v4.0.0.svg?style=flat-square)](https://travis-ci.org/SAP/cf-nodejs-logging-support)
[![Version npm](https://img.shields.io/npm/v/cf-nodejs-logging-support.svg?style=flat-square)](https://www.npmjs.com/package/cf-nodejs-logging-support)[![npm Downloads](https://img.shields.io/npm/dm/cf-nodejs-logging-support.svg?style=flat-square)](https://www.npmjs.com/package/cf-nodejs-logging-support)[![Build Status](https://img.shields.io/travis/SAP/cf-nodejs-logging-support/v4.0.0.svg?style=flat-square)](https://travis-ci.org/SAP/cf-nodejs-logging-support)[![REUSE status](https://api.reuse.software/badge/github.com/SAP/cf-nodejs-logging-support)](https://api.reuse.software/info/github.com/SAP/cf-nodejs-logging-support)

@@ -144,13 +144,4 @@ ## Summary

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. As version 6.0.0 custom fields have to registered before writing them. See Custom fields section.
*NOTE: The logged format for custom_fields changed with version 6.4.0 to adopt to changes made to our handling of custom fields*
With an additional json object to be embedded in to the message (nothing will be added to custom_fields).
```js
info("Test data %j", {"field" :"value"});
// ... "msg":"Test data %j"
// ... "#cf": {"string": [{"k":"field","v":"value","i":"0"}]}...
```
With json object forced to be embedded in to the message (nothing will be added to custom_fields).
```js
info("Test data %j", {"field" :"value"}, {});

@@ -166,2 +157,34 @@ // ... "msg":"Test data {\"field\": \"value\"}" ...

```
### Custom field usage
You can use the custom field feature to add custom fields to your logs.
Keep in mind that the last argument is handled as custom_fields object, if it is an object.
```js
info("Test data", {"field" :"value"});
// ... "msg":"Test data"
// ... "field":"value"...
```
If you use this library with SAP Application Logging Service,
you need to register your custom fields.
This is necessary, because the custom fields will be reported in a fixed order, so they can be ingested correctly in elasticsearch.
```js
log.registerCustomFields(["field"]);
info("Test data", {"field" :"value"});
// ... "msg":"Test data"
// ... "#cf": {"string": [{"k":"field","v":"value","i":"0"}]}...
```
after version 6.5.0, this library will automatically detect, which logging service you are bound to and will
set the logging format accordingly.
for local testing purposes, you can still enforce a specific format like this:
```js
log.overrideCustomFieldFormat("application-logging");
possible values:
"disabled", "all", "application-logging", "cloud-logging", "default"
```
### Logging contexts

@@ -168,0 +191,0 @@

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