feat(log): Formatted console logging with file output

This commit is contained in:
Björn Benouarets
2025-11-10 05:31:51 +01:00
parent b02f602f07
commit da2719b521
2 changed files with 20 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.log
example/app.log

View File

@@ -135,6 +135,24 @@ func (l *MasterLogger) log(level Level, message string, file string, line int, f
}
}
// Skip FormattedEncoder for file writers if JSONEncoder is present
// This ensures files only get JSON format when JSONEncoder is added
if _, isFormatted := encoder.(*FormattedEncoder); isFormatted {
if _, isFile := writer.(*FileWriter); isFile {
// Check if JSONEncoder exists in encoders
hasJSONEncoder := false
for _, e := range l.encoders {
if _, ok := e.(*JSONEncoder); ok {
hasJSONEncoder = true
break
}
}
if hasJSONEncoder {
continue // Don't write formatted to file if JSON encoder exists
}
}
}
var data []byte
var err error