- add godoc for SameLevel and Equal - update package docs and READMEs with new helpers - refresh unreleased release notes - add tests for Printf, HTTP method levels, and level constructors
This commit is contained in:
@@ -135,6 +135,23 @@ httpCache.SetForeground256Color(214)
|
||||
Because `LogLevel` setters mutate the level in place, call them on a variable, not on a temporary value returned by `NewLogLevel(...)`.
|
||||
Short forms such as `SetFgColor` and `SetBgColor` remain available for backward compatibility.
|
||||
|
||||
Common severities also have dedicated helpers:
|
||||
|
||||
```go
|
||||
access := sneklog.NewInfoLogLevelWithColors("access", sneklog.FgCyan, sneklog.BgNone)
|
||||
audit := sneklog.NewWarnLogLevel("audit")
|
||||
```
|
||||
|
||||
HTTP method-specific predefined levels are available out of the box:
|
||||
|
||||
```go
|
||||
level := sneklog.LogLevelForMethod(http.MethodPost)
|
||||
logger.Print(level, "POST /users")
|
||||
```
|
||||
|
||||
When comparing levels, use `SameLevel` if only the severity matters and `Equal`
|
||||
if the full configuration, including colors and attributes, must match.
|
||||
|
||||
## Message replacement
|
||||
|
||||
`AddReplacer(old, new)` replaces matching text in every message before the
|
||||
@@ -157,6 +174,7 @@ An empty `old` value is ignored.
|
||||
|
||||
- `Info`, `Warn`, `Error`, `Debug`, and `Fatal` accept a list of values.
|
||||
- `Infof`, `Warnf`, `Errorf`, `Debugf`, and `Fatalf` use `fmt.Sprintf`.
|
||||
- `Printf(level, format, args...)` formats a message for an explicit `LogLevel`.
|
||||
- The `*ln` methods preserve newline semantics, which is useful for `stdout`, Docker, and line-based collectors.
|
||||
- `Fatal`, `Fatalf`, and `Fatalln` call `os.Exit(1)` after writing the message.
|
||||
- `AddReplacer` masks or rewrites message text before records are sent to writers.
|
||||
|
||||
Reference in New Issue
Block a user