Do not use global logger in middlewares, use the one initialized in res.locals instead

This commit is contained in:
Daniel García Aubert
2020-06-02 09:00:45 +02:00
parent e644201756
commit 62d66f2dbc
11 changed files with 20 additions and 26 deletions
+3 -8
View File
@@ -70,7 +70,6 @@ module.exports = class PreviewTemplateController {
metrics({
enabled: this.config.pubSubMetrics.enabled,
metricsBackend: this.metricsBackend,
logger: global.logger,
tags: metricsTags
}),
credentials(),
@@ -337,17 +336,13 @@ function setContentTypeHeader () {
};
}
function incrementMapViewsError (ctx) {
return `ERROR: failed to increment mapview count for user '${ctx.user}': ${ctx.err}`;
}
function incrementMapViews ({ metadataBackend }) {
return function incrementMapViewsMiddleware (req, res, next) {
const { user, mapConfigProvider } = res.locals;
const { user, mapConfigProvider, logger } = res.locals;
mapConfigProvider.getMapConfig((err, mapConfig) => {
if (err) {
global.logger.info(incrementMapViewsError({ user, err }));
logger.warn(err, `ERROR: failed to increment mapview count for user '${user}'`);
return next();
}
@@ -359,7 +354,7 @@ function incrementMapViews ({ metadataBackend }) {
metadataBackend.incMapviewCount(user, statTag, (err) => {
if (err) {
global.logger.info(incrementMapViewsError({ user, err }));
logger.warn(err, `ERROR: failed to increment mapview count for user '${user}'`);
}
next();