Log the config after loading

This commit is contained in:
2024-12-18 22:16:20 +01:00
parent 7ccd36f0e4
commit f6de4fb839
4 changed files with 34 additions and 40 deletions

View File

@@ -4,6 +4,7 @@ package logging
import (
"log/slog"
"os"
"reflect"
)
// Logger represents the interface for logging operations
@@ -60,6 +61,27 @@ func ParseLogLevel(level string) LogLevel {
}
}
// Redact redacts sensitive fields from a struct based on the `log` struct tag
// if the tag is set to "redact" the field value is replaced with "[REDACTED]"
func Redact(v any) map[string]any {
result := make(map[string]any)
val := reflect.ValueOf(v)
typ := val.Type()
for i := 0; i < val.NumField(); i++ {
field := typ.Field(i)
if tag := field.Tag.Get("log"); tag != "" {
switch tag {
case "redact":
result[field.Name] = "[REDACTED]"
default:
result[field.Name] = val.Field(i).Interface()
}
}
}
return result
}
// Implementation of Logger interface methods
func (l *logger) Debug(msg string, args ...any) {
l.logger.Debug(msg, args...)