Skip to content

Instantly share code, notes, and snippets.

@tegud
Created May 15, 2018 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tegud/40b057fd7a68e576cd844599592aff6c to your computer and use it in GitHub Desktop.
Save tegud/40b057fd7a68e576cd844599592aff6c to your computer and use it in GitHub Desktop.
dynamic log level
const requestContext = require("../request-context");
function getHeaderName(config) {
if (!config.dynamicLogLevel || !config.dynamicLogLevel.header) {
return "x-log-level";
}
return config.dynamicLogLevel.header;
}
module.exports = (config, req, res, next) => {
const header = getHeaderName(config);
if (!req.headers[header]) {
return next();
}
requestContext.setValue("logLevel", req.headers[header]);
next();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment