Create logger middleware to encapsulate its configuration from app
This commit is contained in:
parent
b6989ac82a
commit
3316c2ded3
22
lib/cartodb/middleware/logger.js
Normal file
22
lib/cartodb/middleware/logger.js
Normal file
@ -0,0 +1,22 @@
|
||||
module.exports = function logger (options) {
|
||||
if (!global.log4js || !options.log_format) {
|
||||
return function dummyLoggerMiddleware (req, res, next) {
|
||||
next();
|
||||
};
|
||||
}
|
||||
|
||||
const opts = {
|
||||
level: 'info',
|
||||
// Allowing for unbuffered logging is mainly
|
||||
// used to avoid hanging during unit testing.
|
||||
// TODO: provide an explicit teardown function instead,
|
||||
// releasing any event handler or timer set by
|
||||
// this component.
|
||||
buffer: !options.unbuffered_logging,
|
||||
// optional log format
|
||||
format: options.log_format
|
||||
};
|
||||
const logger = global.log4js.getLogger();
|
||||
|
||||
return global.log4js.connectLogger(logger, opts);
|
||||
};
|
@ -13,6 +13,7 @@ const lzmaMiddleware = require('./middleware/lzma');
|
||||
const errorMiddleware = require('./middleware/error-middleware');
|
||||
const syntaxError = require('./middleware/syntax-error');
|
||||
const servedByHostHeader = require('./middleware/served-by-host-header');
|
||||
const logger = require('./middleware/logger');
|
||||
|
||||
const ControllersFactory = require('./controllers/factory');
|
||||
|
||||
@ -28,6 +29,8 @@ module.exports = function createServer (serverOptions) {
|
||||
|
||||
const app = bootstrap(serverOptions);
|
||||
|
||||
app.use(logger(serverOptions));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.use(servedByHostHeader());
|
||||
@ -39,9 +42,6 @@ module.exports = function createServer (serverOptions) {
|
||||
|
||||
app.use(lzmaMiddleware());
|
||||
|
||||
|
||||
setupLogger(app, serverOptions);
|
||||
|
||||
app.use(cors());
|
||||
app.use(user());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user