feat: add message replacement for log records
Add Logger.AddReplacer to mask or normalize message text before records reach writers. Document replacement behavior in README and package GoDoc, and update the example. Also fix JSON writer edge cases: - avoid panic on empty message lists - preserve newline semantics when the last message already ends with n - keep original message argument types for custom writers when no replacers are configured Update dependencies and add release notes for the next release.
This commit is contained in:
+3
-5
@@ -70,14 +70,12 @@ func (w *LoggerJsonWriter) Write(data []byte) (int, error) {
|
||||
|
||||
// Print encodes the provided record as JSON and writes it to the underlying writer.
|
||||
func (w *LoggerJsonWriter) Print(level LogLevel, prefix string, traceback []*MethodTraceback, messages ...any) error {
|
||||
msg := Map(messages, func(el any) string {
|
||||
return fmt.Sprintf("%v", el)
|
||||
})
|
||||
msg := Map(messages, func(el any) string { return fmt.Sprint(el) })
|
||||
|
||||
newline := false
|
||||
if msg[len(msg)-1] == "\n" {
|
||||
if len(msg) > 0 && strings.HasSuffix(msg[len(msg)-1], "\n") {
|
||||
newline = true
|
||||
msg = msg[:len(msg)-1]
|
||||
msg[len(msg)-1] = strings.TrimSuffix(msg[len(msg)-1], "\n")
|
||||
}
|
||||
|
||||
m := LoggerJsonMessage{
|
||||
|
||||
Reference in New Issue
Block a user