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.6.0 to 6.7.0

logger/log-connect.js

3

index.js

@@ -40,2 +40,5 @@ //loading core logger functionality

break;
case "connect":
effectiveLogger = require("./logger/log-connect");
break;
default:

@@ -42,0 +45,0 @@ effectiveLogger = require("./logger/log-express");

4

logger/log-plainhttp.js

@@ -95,4 +95,4 @@ // Log network activity for express applications

case "header":
if (res._headers)
logObject[configEntry.name] = res._headers[configEntry.source.name];
if (res.getHeader)
logObject[configEntry.name] = res.getHeader(configEntry.source.name);
break;

@@ -99,0 +99,0 @@ case "field":

{
"name": "cf-nodejs-logging-support",
"version": "6.6.0",
"version": "6.7.0",
"description": "Logging tool for Cloud Foundry",

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

@@ -17,3 +17,2 @@ # Node.js Logging Support for Cloud Foundry

## Features

@@ -55,11 +54,33 @@

});
app.listen(3000);
// Formatted log message free of request context
// Formatted log message without request context
log.info("Server is listening on port %d", 3000);
```
### Other Server Libraries
### Other Server Frameworks
The logging library defaults to express middleware behaviour, but it can be forced to work with other server libraries as well:
The logging library defaults to express middleware behaviour, but it can be forced to work with other server frameworks as well:
#### With connect:
```js
var connect = require('connect');
var http = require('http');
var log = require('cf-nodejs-logging-support');
var app = connect();
// Force logger to run the connect version. (default is express, forcing express is also legal)
log.forceLogger("connect");
// Add the logger middleware, so each time a request is received, it is will get logged.
app.use(log.logNetwork);
// Create node.js http server and listen on port
http.createServer(app).listen(3000);
// Same usage as express logger, see minimal example above
```
#### With restify:

@@ -70,10 +91,11 @@ ```js

var app = restify.createServer();
//forces logger to run the restify version. (default is express, forcing express is also legal)
// Force logger to run the restify version. (default is express, forcing express is also legal)
log.forceLogger("restify");
//insert the logger in the server network queue, so each time a https request is recieved, it is will get logged.
// Add the logger middleware, so each time a request is received, it is will get logged.
app.use(log.logNetwork);
//same usage as express logger, see minimal example above
// Same usage as express logger, see minimal example above
```
#### With nodejs http:

@@ -84,7 +106,7 @@ ```js

//forces logger to run the http version.
// Force logger to run the http version.
log.forceLogger("plainhttp");
const server = http.createServer((req, res) => {
//binds logging to the given request for request tracking
// Binds logging to the given request for request tracking
log.logNetwork(req, res);

@@ -96,5 +118,4 @@

});
server.listen(3000);
// Formatted log message free of request context
log.info("Server is listening on port %d", 3000);
```

@@ -122,10 +143,10 @@

- error
- warn
- info
- verbose
- debug
- silly
- `error`
- `warn`
- `info`
- `verbose`
- `debug`
- `silly`
In addition there is an *off* logging level available, which disables logging output completely. This can come in handy for testing. There are so called *convenient methods* for all supported logging levels, which can be called to log a message using the corresponding level. It is also possible to use standard format placeholders equivalent to the [util.format](https://nodejs.org/api/util.html#util_util_format_format_args) method.
In addition there is an `off` logging level available, which disables logging output completely. This can come in handy for testing. There are so called *convenient methods* for all supported logging levels, which can be called to log a message using the corresponding level. It is also possible to use standard format placeholders equivalent to the [util.format](https://nodejs.org/api/util.html#util_util_format_format_args) method.

@@ -163,33 +184,2 @@ Simple message

### 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

@@ -268,7 +258,24 @@

### Custom fields
Custom fields are basically additional key-value pairs added to the logs. As of version 6.0.0 you have to register custom fields, before you can write them. This can be done, by calling following global method:
You can use the custom field feature to add custom fields to your logs.
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-a", "field-b", "field-c"]);
log.registerCustomFields(["field"]);
info("Test data", {"field" :"value"});
// ... "msg":"Test data"
// ... "#cf": {"string": [{"k":"field","v":"value","i":"0"}]}...
```
As of 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"
```
You can now log messages and attach a key-value object as stated in the message logs section.

@@ -322,4 +329,2 @@ ```js

### Sensitive data redaction

@@ -326,0 +331,0 @@ Version 3.0.0 and above implements a sensitive data redaction system, which deactivates the logging of sensitive fields. The field will contain 'redacted' instead of the original content.

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