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:
@@ -13,6 +13,8 @@
|
||||
// - pretty JSON: disabled
|
||||
//
|
||||
// Call Level(DEBUG) to enable all records, including debug messages.
|
||||
// AddReplacer can be used to mask or normalize message text before records are
|
||||
// passed to writers.
|
||||
//
|
||||
// Basic usage:
|
||||
//
|
||||
@@ -20,7 +22,8 @@
|
||||
// Prefix("API").
|
||||
// Level(slog.DEBUG).
|
||||
// PrintTraceback(true).
|
||||
// JsonPretty(true)
|
||||
// JsonPretty(true).
|
||||
// AddReplacer("secret-token", "<redacted>")
|
||||
//
|
||||
// text := logger.CreateTextStdoutWriter()
|
||||
// jsonFile, err := logger.CreateJsonFileWriter("logs/app.json")
|
||||
@@ -29,7 +32,7 @@
|
||||
// }
|
||||
//
|
||||
// logger.AddWriters(text, jsonFile)
|
||||
// logger.Infoln("service started")
|
||||
// logger.Infoln("service started", "secret-token")
|
||||
//
|
||||
// if err := logger.Close(); err != nil {
|
||||
// panic(err)
|
||||
|
||||
Reference in New Issue
Block a user