(chore): document and test new LogLevel APIs
Golang lint / lint (push) Successful in 47s

- 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:
2026-04-27 17:04:41 +03:00
parent 812caed471
commit b7fa3f7606
6 changed files with 197 additions and 2 deletions
+18
View File
@@ -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.