Skip to content

Commit

Permalink
Auth: log module name with IRMA log entries (#1268)
Browse files Browse the repository at this point in the history
Co-authored-by: Rein Krul <[email protected]>
  • Loading branch information
reinkrul and reinkrul authored Jul 28, 2022
1 parent 7b9a632 commit d5e1875
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions auth/services/irma/irmaconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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))
}

0 comments on commit d5e1875

Please sign in to comment.