feat(log): Formatted console logging with file output
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.log
|
||||||
|
example/app.log
|
||||||
18
logger.go
18
logger.go
@@ -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 data []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user