mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 16:04:23 +00:00
Log the config after loading
This commit is contained in:
@@ -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...)
|
||||
|
||||
Reference in New Issue
Block a user