Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-bunyan

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-bunyan - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

83

lib/index.js
'use strict';
/**
* Module dependencies.
*/
var hoek = require('hoek');
/**
* Constants.

@@ -10,2 +16,37 @@ */

/**
* Event logger.
*/
function logEvent(ctx, data, request) {
var obj = {};
var msg = '';
if (ctx.includeTags) {
obj.tags = ctx.joinTags ? data.tags.join(ctx.joinTags) : data.tags;
}
if (request) obj.req_id = request.id;
if (typeof data.data === 'string') {
msg = data.data;
} else if (ctx.includeData && data.data !== undefined) {
if (ctx.mergeData) {
try {
hoek.merge(obj, data.data);
if (obj.id === obj.req_id) delete obj.id;
} catch (err) {
obj.data = data.data;
}
} else {
obj.data = data.data;
}
} else if (ctx.skipUndefined) {
return;
}
ctx.log[ctx.level](obj, msg);
}
/**
* Plugin.

@@ -22,2 +63,12 @@ */

delete options.logger;
delete options.handler;
options = hoek.applyToDefaults({
includeTags: false,
includeData: true,
mergeData: false,
skipUndefined: true,
}, options);
server.ext('onRequest', function(request, next) {

@@ -43,3 +94,7 @@ var rlog = request.log;

log: log,
logUndefined: options.logUndefined,
includeTags: options.includeTags,
includeData: options.includeData,
mergeData: options.mergeData,
skipUndefined: options.skipUndefined,
joinTags: options.joinTags,
};

@@ -51,11 +106,3 @@

var emit = ctx.log[ctx.level].bind(ctx.log);
if (typeof data.data === 'string') {
emit({ tags: data.tags }, data.data);
} else if (data.data !== undefined) {
emit({ data: data.data, tags: data.tags });
} else if (ctx.logUndefined) {
emit({ tags: data.tags });
}
logEvent(ctx, data);
});

@@ -67,3 +114,7 @@

log: log,
logUndefined: options.logUndefined,
includeTags: options.includeTags,
includeData: options.includeData,
mergeData: options.mergeData,
skipUndefined: options.skipUndefined,
joinTags: options.joinTags,
};

@@ -75,11 +126,3 @@

var emit = ctx.log[ctx.level].bind(ctx.log);
if (typeof data.data === 'string') {
emit({ req_id: request.id, tags: data.tags }, data.data);
} else if (data.data !== undefined) {
emit({ data: data.data, req_id: request.id, tags: data.tags });
} else if (ctx.logUndefined) {
emit({ req_id: request.id, tags: data.tags });
}
logEvent(ctx, data, request);
});

@@ -86,0 +129,0 @@

{
"name": "hapi-bunyan",
"version": "0.1.0",
"version": "0.2.0",
"main": "./lib",

@@ -29,3 +29,6 @@ "description": "Simple Bunyan logging in Hapi",

},
"homepage": "https://github.com/silas/hapi-bunyan"
"homepage": "https://github.com/silas/hapi-bunyan",
"dependencies": {
"hoek": "^2.4.1"
}
}

@@ -10,4 +10,8 @@ # Hapi Bunyan

* logger (Object): Bunyan logger object
* handler (Function, optional): Custom event handler, this function can return true if it handled the event. The call has `log`, `level`, and `logUndefined` binded to `this`. Both `level` and `logUndefined` can be modified in place.
* logUndefined (Boolean, default: false): Show events events with no data.
* handler (Function, optional): custom event handler, this function can return `true` if it handled the event.
* skipUndefined (Boolean, default: true): don't log events with `undefined` data.
* includeData (Boolean, default: true): include data in log events.
* mergeData (Boolean, default: false): when the event data is an object merge it into the log data.
* includeTags (Boolean, default: false): include tags in log event.
* joinTags (String, optional): join tags using the specified character.

@@ -14,0 +18,0 @@ ## Example

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