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'; |
||||
|
||||
var peliasConfig = require( 'pelias-config' ).generate().api; |
||||
var morgan = require( 'morgan' ); |
||||
var through = require( 'through2' ); |
||||
var peliasLogger = require( 'pelias-logger' ).get( 'api' ); |
||||
|
||||
module.exports = peliasConfig.accessLog ? |
||||
morgan( peliasConfig.accessLog ) : |
||||
function noop(req, res, next){ |
||||
function createAccessLogger( logFormat ){ |
||||
return morgan( logFormat, { |
||||
stream: through( function write( ln, _, next ){ |
||||
peliasLogger.info( ln.toString().trim() ); |
||||
next(); |
||||
}; |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
module.exports = createAccessLogger; |
||||
|
Loading…
Reference in new issue