mirror of https://github.com/pelias/api.git
Browse Source
(app, middleware/access_log).js -Move the logic that determines whether access logging is necessary to app.js, since that allows us to maintain the style of `app.use(require(/* desired middleware module */))` inside `app.js` without returning a "noop" middleware from `middleware/access_log.js` in the case that it's unnecessary.pull/123/head
Severyn Kozak
10 years ago
3 changed files with 18 additions and 8 deletions
@ -1,14 +1,20 @@ |
|||||||
/** |
/** |
||||||
* Print out access logs. |
* Create a middleware that prints access logs via pelias-logger. |
||||||
*/ |
*/ |
||||||
|
|
||||||
'use strict'; |
'use strict'; |
||||||
|
|
||||||
var peliasConfig = require( 'pelias-config' ).generate().api; |
|
||||||
var morgan = require( 'morgan' ); |
var morgan = require( 'morgan' ); |
||||||
|
var through = require( 'through2' ); |
||||||
|
var peliasLogger = require( 'pelias-logger' ).get( 'api' ); |
||||||
|
|
||||||
module.exports = peliasConfig.accessLog ? |
function createAccessLogger( logFormat ){ |
||||||
morgan( peliasConfig.accessLog ) : |
return morgan( logFormat, { |
||||||
function noop(req, res, next){ |
stream: through( function write( ln, _, next ){ |
||||||
next(); |
peliasLogger.info( ln.toString().trim() ); |
||||||
}; |
next(); |
||||||
|
}) |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = createAccessLogger; |
||||||
|
Loading…
Reference in new issue