From 877e1e90a5bc4785e23a4ab23d1ac7410695c145 Mon Sep 17 00:00:00 2001 From: Severyn Kozak Date: Mon, 4 May 2015 16:45:52 -0400 Subject: [PATCH] Add an access log middleware. middleware/access_log.js, package.json -Add middleware for printing out access logs. -Add necessary dependencies. --- app.js | 2 ++ middleware/access_log.js | 14 ++++++++++++++ package.json | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 middleware/access_log.js diff --git a/app.js b/app.js index b0f65801..29897d73 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,8 @@ var app = require('express')(); +app.use( require( './middleware/access_log' ) ); + /** ----------------------- middleware ----------------------- **/ app.use( require('./middleware/headers') ); diff --git a/middleware/access_log.js b/middleware/access_log.js new file mode 100644 index 00000000..ff79eb00 --- /dev/null +++ b/middleware/access_log.js @@ -0,0 +1,14 @@ +/** + * Print out access logs. + */ + +'use strict'; + +var peliasConfig = require( 'pelias-config' ).generate().api; +var morgan = require( 'morgan' ); + +module.exports = peliasConfig.accessLog ? + morgan( peliasConfig.accessLog ) : + function noop(req, res, next){ + next(); + }; diff --git a/package.json b/package.json index ae77f1ae..f64ca731 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,8 @@ "is-object": "^1.0.1", "markdown": "0.5.0", "pelias-esclient": "0.0.25", + "morgan": "1.5.2", + "pelias-config": "^0.1.4", "pelias-suggester-pipeline": "2.0.2" }, "devDependencies": {