Comparing version 0.14.1 to 0.15.0
@@ -83,1 +83,11 @@ logfmt = require('../logfmt'); | ||
} | ||
exports.error = function(err) { | ||
var id = Math.random().toString().slice(2, 12); | ||
this.log({ error:true, id:id, message:err.message }); | ||
var stack = err.stack.split('\n'); | ||
for (var line in stack) { | ||
if (line >= (this.maxErrorLines || 10)) break; | ||
this.log({ error:true, id:id, line:line, trace:stack[line] }); | ||
} | ||
} |
@@ -11,5 +11,8 @@ var logfmt = function(){ | ||
this.namespace = logger.namespace; | ||
this.error = logger.error; | ||
this.requestLogger = require('./lib/request_logger'); | ||
this.maxErrorLines = 10; | ||
//Syncronous Body Parser | ||
@@ -16,0 +19,0 @@ var bodyParser = require('./lib/body_parser') |
{ | ||
"name": "logfmt", | ||
"version": "0.14.1", | ||
"version": "0.15.0", | ||
"description": "Key-Value log line parser", | ||
"main": "logfmt.js", | ||
"scripts": { | ||
"test": "./test/test" | ||
"test": "mocha" | ||
}, | ||
@@ -18,3 +18,3 @@ "bin": { | ||
"devDependencies": { | ||
"express": "3.*", | ||
"express": "3.3.x", | ||
"mocha": "*", | ||
@@ -21,0 +21,0 @@ "restify": "*" |
# node-logfmt | ||
[![Build Status](https://travis-ci.org/csquared/node-logfmt.png)](https://travis-ci.org/csquared/node-logfmt) | ||
"logfmt" is the name for a [key value logging convention](https://github.com/kr/logfmt) we've adopted at Heroku. | ||
@@ -168,2 +171,14 @@ | ||
``` | ||
### logging errors | ||
`logfmt.error()` Accepts a Javascript `Error` object and converts it to logfmt format | ||
```javascript | ||
var logfmt = require('logfmmt'); | ||
logfmt.error(new Error('test error')); | ||
//=> at=error id=12345 message="test error" | ||
//=> at=error id=12345 line=0 trace="Error: test error" | ||
//=> ... | ||
``` | ||
## express/restify logging middleware | ||
@@ -170,0 +185,0 @@ |
var logfmt = require('../logfmt'), | ||
stream = require('stream'), | ||
stream = require('readable-stream'), | ||
assert = require('assert'); | ||
@@ -4,0 +4,0 @@ |
var logfmt = require('../logfmt'), | ||
stream = require('stream'), | ||
stream = require('readable-stream'), | ||
assert = require('assert'); | ||
@@ -4,0 +4,0 @@ |
@@ -42,6 +42,6 @@ var logfmt = new require('../logfmt'), | ||
var actual = logfmt.stream.logline; | ||
assert(/^foo=bar elapsed=\dms\n$/.test(actual), actual) | ||
assert(/^foo=bar elapsed=\d+ms\n$/.test(actual), actual) | ||
logger.log({moar: 'data'}); | ||
var actual = logfmt.stream.logline; | ||
assert(/^moar=data foo=bar elapsed=\dms\n$/.test(actual), actual) | ||
assert(/^moar=data foo=bar elapsed=\d+ms\n$/.test(actual), actual) | ||
done(); | ||
@@ -69,3 +69,3 @@ }) | ||
var actual = logfmt.stream.logline; | ||
assert(/^foo=bar time=\dms\n$/.test(actual), actual) | ||
assert(/^foo=bar time=\d+ms\n$/.test(actual), actual) | ||
done(); | ||
@@ -80,3 +80,3 @@ }) | ||
var actual = mock_sink.logline; | ||
assert(/^foo=bar elapsed=\dms\n$/.test(actual), actual) | ||
assert(/^foo=bar elapsed=\d+ms\n$/.test(actual), actual) | ||
done(); | ||
@@ -94,7 +94,7 @@ }) | ||
var actual = mock_sink.logline; | ||
assert(/^foo=bar elapsed=\dms\n$/.test(actual), actual) | ||
assert(/^foo=bar elapsed=\d+ms\n$/.test(actual), actual) | ||
var wrapped = function() { | ||
logger.log({bar: 'foo'}, mock_sink); | ||
var actual = mock_sink.logline; | ||
assert(/^bar=foo elapsed=2\dms\n$/.test(actual), actual) | ||
assert(/^bar=foo elapsed=2\d+ms\n$/.test(actual), actual) | ||
done(); | ||
@@ -101,0 +101,0 @@ } |
exports = module.exports = function OutStream(){ | ||
this.lines = []; | ||
this.logline = ''; | ||
this.write = function(string) { | ||
this.logline = string; | ||
this.lines.push(string); | ||
} | ||
} |
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
52139
43
1198
368