From d5e1875773aa6e12cd38f7e92d3496dc3c14e7cb Mon Sep 17 00:00:00 2001 From: reinkrul Date: Thu, 28 Jul 2022 07:22:26 +0200 Subject: [PATCH] Auth: log module name with IRMA log entries (#1268) Co-authored-by: Rein Krul --- auth/services/irma/irmaconfig.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/auth/services/irma/irmaconfig.go b/auth/services/irma/irmaconfig.go index fd1b960206..bbce7e8979 100644 --- a/auth/services/irma/irmaconfig.go +++ b/auth/services/irma/irmaconfig.go @@ -54,12 +54,23 @@ func GetIrmaConfig(validatorConfig ValidatorConfig) (irmaConfig *irma.Configurat // GetIrmaServer creates and starts the irma server instance. // The server can be used by a IRMA client like the app to handle IRMA sessions func GetIrmaServer(validatorConfig ValidatorConfig, irmaConfig *irma.Configuration) (*irmaserver.Server, error) { - logger := log.Logger().Logger + // Customize logger to have it clearly log "IRMA" in module field. + // We need a decorator because IRMA config takes a logrus.Logger instead of logrus.Entry + logger := *logrus.StandardLogger() + formatter := logger.Formatter + logger.Formatter = &decoratingFormatter{ + formatter: formatter, + decorator: func(entry *logrus.Entry) *logrus.Entry { + entry.Data["module"] = "Auth/IRMA" + return entry + }, + } + config := &server.Configuration{ IrmaConfiguration: irmaConfig, URL: validatorConfig.PublicURL + IrmaMountPath, - Logger: logger, - Verbose: irmaLogLevel(logger), + Logger: &logger, + Verbose: irmaLogLevel(&logger), SchemesPath: validatorConfig.IrmaConfigPath, DisableSchemesUpdate: !validatorConfig.AutoUpdateIrmaSchemas, } @@ -80,3 +91,12 @@ func irmaLogLevel(logger *logrus.Logger) int { return 0 } } + +type decoratingFormatter struct { + formatter logrus.Formatter + decorator func(entry *logrus.Entry) *logrus.Entry +} + +func (f decoratingFormatter) Format(entry *logrus.Entry) ([]byte, error) { + return f.formatter.Format(f.decorator(entry)) +}