hapi-ot-logger
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -16,3 +16,3 @@ var os = require("os"), | ||
host: cfg.host, | ||
sequencenumber: cfg.sequencenumber, | ||
sequencenumber: cfg.sequencenumber | ||
}; | ||
@@ -23,2 +23,6 @@ | ||
_dispatch = function(log){ | ||
if (cfg.validate && !cfg.validate(log)) { | ||
return; | ||
} | ||
if(cfg.console){ | ||
@@ -25,0 +29,0 @@ consoleWriter.log(log); |
{ | ||
"name": "hapi-ot-logger", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "logger conforming to ot standards", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,7 +10,9 @@ #Hapi-ot-logger | ||
```npm install hapi-ot-logger``` | ||
```shell | ||
npm install hapi-ot-logger | ||
``` | ||
usage: | ||
``` | ||
```javascript | ||
var hapi = require("hapi"); | ||
@@ -35,4 +37,7 @@ | ||
}, | ||
console: true // optional console output for debugging, default: false | ||
payload: false // include the request payload (request.payload stringified), default: false | ||
console: true, // optional console output for debugging, default: false | ||
payload: false, // include the request payload (request.payload stringified), default: false | ||
validate: function(log) { // validates that a message should be logged (default to always valid) | ||
return log.logname === 'request' && log.headers['user-agent'] !== 'noisy-spider'; | ||
} | ||
} | ||
@@ -39,0 +44,0 @@ }], function(err){ |
@@ -48,3 +48,6 @@ describe('logger tests', function(){ | ||
}, | ||
payload: true | ||
payload: true, | ||
validate: function(log) { | ||
return log.logname === 'request' && log.headers['user-agent'] !== 'spider'; | ||
} | ||
}; | ||
@@ -55,114 +58,172 @@ done(); | ||
it('should register the plugin', function(done){ | ||
plugin.register(p, options, function(){ | ||
events.length.should.eql(3); | ||
events[0].type.should.eql('tail'); | ||
events[1].type.should.eql('log'); | ||
events[2].type.should.eql('internalError'); | ||
done(); | ||
describe('setup', function() { | ||
it('should register the plugin', function(done){ | ||
plugin.register(p, options, function(){ | ||
events.length.should.eql(3); | ||
events[0].type.should.eql('tail'); | ||
events[1].type.should.eql('log'); | ||
events[2].type.should.eql('internalError'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}) | ||
it('should handle a request', function(done){ | ||
events[0].handler({ | ||
method: 'get', | ||
path: '/foo', | ||
query: { | ||
flarg: 'glarg' | ||
}, | ||
response: { | ||
statusCode: 200 | ||
}, | ||
info: { | ||
received: Date.now() | ||
}, | ||
getLog: function(){ return []; }, | ||
headers: { | ||
"ot-requestid": "abcd-1234-abcd-1234", | ||
"user-agent": "tests", | ||
"ot-userid": "user1234", | ||
"ot-sessionid": "1234-abcd-1234-abcd", | ||
"ot-referringhost": "referringhost", | ||
"ot-referringservice": "referringservice", | ||
"accept-language": "en-GB,en;q=0.8" | ||
} | ||
describe('simple requests', function() { | ||
it('should handle a request', function(done){ | ||
events[0].handler({ | ||
method: 'get', | ||
path: '/foo', | ||
query: { | ||
flarg: 'glarg' | ||
}, | ||
response: { | ||
statusCode: 200 | ||
}, | ||
info: { | ||
received: Date.now() | ||
}, | ||
getLog: function(){ return []; }, | ||
headers: { | ||
"ot-requestid": "abcd-1234-abcd-1234", | ||
"user-agent": "tests", | ||
"ot-userid": "user1234", | ||
"ot-sessionid": "1234-abcd-1234-abcd", | ||
"ot-referringhost": "referringhost", | ||
"ot-referringservice": "referringservice", | ||
"accept-language": "en-GB,en;q=0.8" | ||
} | ||
}); | ||
setTimeout(function(){ | ||
joi.validate(logs[0], schema.request, function(err){ | ||
done(err); | ||
}); | ||
}, 10); | ||
}); | ||
setTimeout(function(){ | ||
joi.validate(logs[0], schema.request, function(err){ | ||
done(err); | ||
it('should include the body from a PUT/POST request', function(done){ | ||
events[0].handler({ | ||
method: 'post', | ||
path: '/foo', | ||
query: { | ||
flarg: 'glarg' | ||
}, | ||
payload: { | ||
foo: 'bar', | ||
baz: { flarg: 'glarg' } | ||
}, | ||
response: { | ||
statusCode: 200 | ||
}, | ||
info: { | ||
received: Date.now() | ||
}, | ||
getLog: function(){ return []; }, | ||
headers: { | ||
"ot-requestid": "abcd-1234-abcd-1234", | ||
"user-agent": "tests", | ||
"ot-userid": "user1234", | ||
"ot-sessionid": "1234-abcd-1234-abcd", | ||
"ot-referringhost": "referringhost", | ||
"ot-referringservice": "referringservice", | ||
"accept-language": "en-GB,en;q=0.8" | ||
} | ||
}); | ||
}, 10); | ||
}); | ||
it('should include the body from a PUT/POST request', function(done){ | ||
events[0].handler({ | ||
method: 'post', | ||
path: '/foo', | ||
query: { | ||
flarg: 'glarg' | ||
}, | ||
payload: { | ||
foo: 'bar', | ||
baz: { flarg: 'glarg' } | ||
}, | ||
response: { | ||
statusCode: 200 | ||
}, | ||
info: { | ||
received: Date.now() | ||
}, | ||
getLog: function(){ return []; }, | ||
headers: { | ||
"ot-requestid": "abcd-1234-abcd-1234", | ||
"user-agent": "tests", | ||
"ot-userid": "user1234", | ||
"ot-sessionid": "1234-abcd-1234-abcd", | ||
"ot-referringhost": "referringhost", | ||
"ot-referringservice": "referringservice", | ||
"accept-language": "en-GB,en;q=0.8" | ||
} | ||
setTimeout(function(){ | ||
joi.validate(logs[1], schema.request, function(err){ | ||
logs[1].payload.should.equal('{"foo":"bar","baz":{"flarg":"glarg"}}'); | ||
done(err); | ||
}); | ||
}, 10); | ||
}); | ||
}); | ||
setTimeout(function(){ | ||
joi.validate(logs[1], schema.request, function(err){ | ||
logs[1].payload.should.equal('{"foo":"bar","baz":{"flarg":"glarg"}}'); | ||
done(err); | ||
describe('request validation', function(){ | ||
it('does not log if validate function fails check', function(done) { | ||
events[0].handler({ | ||
method: 'get', | ||
path: '/foo', | ||
response: { | ||
statusCode: 200 | ||
}, | ||
info: { | ||
received: Date.now() | ||
}, | ||
getLog: function(){ return []; }, | ||
headers: { | ||
"user-agent": "spider" | ||
} | ||
}); | ||
}, 10); | ||
}); | ||
it('should handle a log', function(done){ | ||
events[1].handler({ | ||
data: { | ||
somestuff: 'blarg' | ||
}, | ||
tags: ['tag1', 'tag2'] | ||
setTimeout(function(){ | ||
if (logs[2]) { | ||
return done(Error("There should not be a second log")); | ||
} | ||
done(); | ||
}, 10); | ||
}); | ||
setTimeout(function(){ | ||
joi.validate(logs[2], schema.log, function(err){ | ||
done(err); | ||
it('does log if validate function passes check', function(done) { | ||
events[0].handler({ | ||
method: 'get', | ||
path: '/foo', | ||
response: { | ||
statusCode: 200 | ||
}, | ||
info: { | ||
received: Date.now() | ||
}, | ||
getLog: function(){ return []; }, | ||
headers: { | ||
"user-agent": "mozilla" | ||
} | ||
}); | ||
}, 10); | ||
}); | ||
it('should handle an error', function(done){ | ||
events[2].handler({}, { | ||
message: 'ohes noes it borked' | ||
setTimeout(function(){ | ||
if (!logs[2]) { | ||
return done(Error("There should be a second log")); | ||
} | ||
done(); | ||
}, 10); | ||
}); | ||
}); | ||
setTimeout(function(){ | ||
joi.validate(logs[3], schema.error, function(err){ | ||
done(err); | ||
describe('logs', function() { | ||
it('should handle a log', function(done){ | ||
events[1].handler({ | ||
data: { | ||
somestuff: 'blarg' | ||
}, | ||
tags: ['tag1', 'tag2'] | ||
}); | ||
}, 10); | ||
setTimeout(function(){ | ||
joi.validate(logs[3], schema.log, function(err){ | ||
done(err); | ||
}); | ||
}, 10); | ||
}); | ||
}); | ||
it('should return immediately (without an error) when an error occurs', function(){ | ||
discon = true; | ||
events[2].handler({}, { | ||
message: 'ohes noes it borked' | ||
describe('errors', function() { | ||
it('should handle an error', function(done){ | ||
events[2].handler({}, { | ||
message: 'ohes noes it borked' | ||
}); | ||
setTimeout(function(){ | ||
joi.validate(logs[4], schema.error, function(err){ | ||
done(err); | ||
}); | ||
}, 10); | ||
}); | ||
it('should return immediately (without an error) when an error occurs', function(){ | ||
discon = true; | ||
events[2].handler({}, { | ||
message: 'ohes noes it borked' | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16692
425
53