(new): prepare v2.1.0 release
Golang lint / lint (push) Successful in 24s

- add custom LogLevel constructors and richer color configuration
- support ANSI, 256-color, RGB, and text attributes on LogLevel
- introduce clearer preferred APIs such as NewLogger and SetName
- preserve backward compatibility with deprecated wrappers for v2.0.1 APIs
- restore legacy ColorStringBuilder signatures as compatibility wrappers
- fix newline separator handling in Println-style output
- add tests for color precedence, deprecated aliases, and LogLevel attributes
- update GoDoc and bilingual README documentation
This commit is contained in:
2026-04-27 15:42:24 +03:00
parent b4c9203a79
commit 3eac1851ec
11 changed files with 669 additions and 118 deletions
+22 -4
View File
@@ -32,9 +32,9 @@ import (
)
func main() {
logger := sneklog.CreateLogger().
Prefix("API").
Level(sneklog.DEBUG).
logger := sneklog.NewLogger().
SetName("API").
SetLevel(sneklog.DEBUG).
AddReplacer("SOME_SECRET", "<redacted>")
text := logger.CreateTextStdoutWriter()
@@ -59,7 +59,7 @@ func main() {
## Defaults
`CreateLogger()` starts with:
`NewLogger()` starts with:
- `Prefix("LOG")`
- `Level(sneklog.FATAL)`
@@ -67,6 +67,8 @@ func main() {
- text formatter: `sneklog.DefaultTextFormatter`
- JSON formatter: `sneklog.DefaultJsonFormatter`
`CreateLogger()` is still available for backward compatibility.
Important: with the current level ordering, `Level(sneklog.FATAL)` allows `INFO`, `WARN`, `ERROR`, and `FATAL`, but not `DEBUG`. Use `Level(sneklog.DEBUG)` to enable every level.
## Writers and ownership
@@ -117,6 +119,22 @@ JSON writers emit objects with this shape:
When `JsonPretty(true)` is enabled, JSON is indented.
## Custom levels and colors
You can define your own levels and assign ANSI, 256-color, or RGB colors, plus text attributes such as `Bold` or `Italic`.
```go
httpDelete := sneklog.NewLogLevel(0, "delete")
httpDelete.SetBackgroundRGB(128, 0, 0)
httpDelete.AddAttribute(sneklog.Italic).AddAttribute(sneklog.Bold)
httpCache := sneklog.NewLogLevel(0, "cache")
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.
## Message replacement
`AddReplacer(old, new)` replaces matching text in every message before the