Comparing version 1.8.2 to 1.9.0
@@ -0,1 +1,11 @@ | ||
1.9.0 / 2017-09-26 | ||
================== | ||
* Use `res.headersSent` when available | ||
* deps: basic-auth@~2.0.0 | ||
- Use `safe-buffer` for improved Buffer API | ||
* deps: debug@2.6.9 | ||
* deps: depd@~1.1.1 | ||
- Remove unnecessary `Buffer` loading | ||
1.8.2 / 2017-05-23 | ||
@@ -2,0 +12,0 @@ ================== |
22
index.js
@@ -6,3 +6,3 @@ /*! | ||
* Copyright(c) 2014 Jonathan Ong | ||
* Copyright(c) 2014-2015 Douglas Christopher Wilson | ||
* Copyright(c) 2014-2017 Douglas Christopher Wilson | ||
* MIT Licensed | ||
@@ -186,3 +186,3 @@ */ | ||
// get the status code if response written | ||
var status = res._header | ||
var status = headersSent(res) | ||
? res.statusCode | ||
@@ -266,3 +266,3 @@ : undefined | ||
morgan.token('status', function getStatusToken (req, res) { | ||
return res._header | ||
return headersSent(res) | ||
? String(res.statusCode) | ||
@@ -334,3 +334,3 @@ : undefined | ||
morgan.token('res', function getResponseHeader (req, res, field) { | ||
if (!res._header) { | ||
if (!headersSent(res)) { | ||
return undefined | ||
@@ -477,2 +477,16 @@ } | ||
/** | ||
* Determine if the response headers have been sent. | ||
* | ||
* @param {object} res | ||
* @returns {boolean} | ||
* @private | ||
*/ | ||
function headersSent (res) { | ||
return typeof res.headersSent !== 'boolean' | ||
? Boolean(res._header) | ||
: res.headersSent | ||
} | ||
/** | ||
* Pad number to two digits. | ||
@@ -479,0 +493,0 @@ * |
{ | ||
"name": "morgan", | ||
"description": "HTTP request logger middleware for node.js", | ||
"version": "1.8.2", | ||
"version": "1.9.0", | ||
"contributors": [ | ||
@@ -18,5 +18,5 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"dependencies": { | ||
"basic-auth": "~1.1.0", | ||
"debug": "2.6.8", | ||
"depd": "~1.1.0", | ||
"basic-auth": "~2.0.0", | ||
"debug": "2.6.9", | ||
"depd": "~1.1.1", | ||
"on-finished": "~2.3.0", | ||
@@ -28,5 +28,5 @@ "on-headers": "~1.0.1" | ||
"eslint-config-standard": "10.2.1", | ||
"eslint-plugin-import": "2.2.0", | ||
"eslint-plugin-import": "2.7.0", | ||
"eslint-plugin-markdown": "1.0.0-beta.6", | ||
"eslint-plugin-node": "4.2.2", | ||
"eslint-plugin-node": "5.1.1", | ||
"eslint-plugin-promise": "3.5.0", | ||
@@ -36,3 +36,3 @@ "eslint-plugin-standard": "3.0.1", | ||
"mocha": "2.5.3", | ||
"split": "1.0.0", | ||
"split": "1.0.1", | ||
"supertest": "1.1.0" | ||
@@ -39,0 +39,0 @@ }, |
@@ -28,3 +28,3 @@ # morgan | ||
The `format` function will be called with three arguments `tokens`, `req`, and `res`, | ||
where `tokens` is object with all defined tokens, `req` is the HTTP request and `res` | ||
where `tokens` is an object with all defined tokens, `req` is the HTTP request and `res` | ||
is the HTTP response. The function is expected to return a string that will be the log | ||
@@ -37,3 +37,3 @@ line, or `undefined` / `null` to skip logging. | ||
``` | ||
```js | ||
morgan('tiny') | ||
@@ -341,2 +341,37 @@ ``` | ||
### split / dual logging | ||
The `morgan` middleware can be used as many times as needed, enabling | ||
combinations like: | ||
* Log entry on request and one on response | ||
* Log all requests to file, but errors to console | ||
* ... and more! | ||
Sample app that will log all requests to a file using Apache format, but | ||
error responses are logged to the console: | ||
```js | ||
var express = require('express') | ||
var fs = require('fs') | ||
var morgan = require('morgan') | ||
var path = require('path') | ||
var app = express() | ||
// log only 4xx and 5xx responses to console | ||
app.use(morgan('dev', { | ||
skip: function (req, res) { return res.statusCode < 400 } | ||
})) | ||
// log all requests to access.log | ||
app.use(morgan('common', { | ||
stream: fs.createWriteStream(path.join(__dirname, 'access.log'), {flags: 'a'}) | ||
})) | ||
app.get('/', function (req, res) { | ||
res.send('hello, world!') | ||
}) | ||
``` | ||
### use custom token formats | ||
@@ -343,0 +378,0 @@ |
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
28501
412
416
+ Addedbasic-auth@2.0.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
- Removedbasic-auth@1.1.0(transitive)
- Removeddebug@2.6.8(transitive)
Updatedbasic-auth@~2.0.0
Updateddebug@2.6.9
Updateddepd@~1.1.1