CartoDB-SQL-API/lib/api/middlewares/logger.js
Esther Lozano 419adea234
Add pubsub metrics (#642)
* Create middleware and service for pubsub metrics

* Use pubsub middleware for all request

* Replace isEnabled with isDisabled to avoid negation

* Use new headers names

* Add acceptance and unit tests

* Remove commented log calls

* Remove only filters in tests

Remove typo

* Refactor service to ease integration test

* Fix interaction with query controller

* Use middleware at api-router and test all controllers

* Rename user middleware function

* Use sinon latest version

* Create middleware and service for pubsub metrics

* Use pubsub middleware for all request

* Replace isEnabled with isDisabled to avoid negation

* Use new headers names

* Add acceptance and unit tests

* Remove commented log calls

* Remove only filters in tests

Remove typo

* Refactor service to ease integration test

* Fix interaction with query controller

* Use middleware at api-router and test all controllers

* Rename user middleware function

* Use sinon latest version

* Fix tests

* Fix typos

* Checks if pubsub config exists to enable the service

* Fix typo

* Normalize headers values for pubsub

* Trim fields when normalizing

* Trim fields when normalizing
2020-02-26 17:19:06 +01:00

28 lines
922 B
JavaScript

'use strict';
module.exports = function logger () {
if (!global.log4js) {
return function dummyLoggerMiddleware (req, res, next) {
next();
};
}
const options = {
level: 'info',
buffer: true,
// log4js provides a tokens solution as express but it does not provide the request/response in the callback.
// Thus it is not possible to extract relevant information from them.
// This is a workaround to be able to access request/response.
format: function (req, res, format) {
const defaultFormat = ':remote-addr :method :req[Host]:url :status :response-time ms -> :res[Content-Type]';
const logFormat = global.settings.log_format || defaultFormat;
return format(logFormat);
}
};
const logger = global.log4js.getLogger();
return global.log4js.connectLogger(logger, options);
};