(refactor): prepare breaking v2 API
- rename package to sneklog and move module to /v2 - replace text output flags with writer formatters - remove external color dependencies - update migration notes and coverage
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# slog
|
||||
# SNekLog (ScuroNeko Logger)
|
||||
|
||||
Small structured logger for Go with text and JSON output, multiple writers, and optional traceback metadata.
|
||||
|
||||
@@ -17,7 +17,7 @@ Russian version: [README_ru.md](README_ru.md)
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
go get git.scuroneko.dev/scuroneko/slog
|
||||
go get git.scuroneko.dev/scuroneko/slog/v2
|
||||
```
|
||||
|
||||
## Quick start
|
||||
@@ -28,15 +28,13 @@ package main
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/slog"
|
||||
"git.scuroneko.dev/scuroneko/slog/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := slog.CreateLogger().
|
||||
logger := sneklog.CreateLogger().
|
||||
Prefix("API").
|
||||
Level(slog.DEBUG).
|
||||
PrintTraceback(true).
|
||||
JsonPretty(true).
|
||||
Level(sneklog.DEBUG).
|
||||
AddReplacer("SOME_SECRET", "<redacted>")
|
||||
|
||||
text := logger.CreateTextStdoutWriter()
|
||||
@@ -64,12 +62,12 @@ func main() {
|
||||
`CreateLogger()` starts with:
|
||||
|
||||
- `Prefix("LOG")`
|
||||
- `Level(slog.FATAL)`
|
||||
- `PrintTime(true)`
|
||||
- `PrintTraceback(false)`
|
||||
- `Level(sneklog.FATAL)`
|
||||
- `JsonPretty(false)`
|
||||
- text formatter: `sneklog.DefaultTextFormatter`
|
||||
- JSON formatter: `sneklog.DefaultJsonFormatter`
|
||||
|
||||
Important: with the current level ordering, `Level(slog.FATAL)` allows `INFO`, `WARN`, `ERROR`, and `FATAL`, but not `DEBUG`. Use `Level(slog.DEBUG)` to enable every level.
|
||||
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
|
||||
|
||||
@@ -92,10 +90,10 @@ This makes it safe to plug in `bytes.Buffer`, network writers, and other externa
|
||||
Text writers render records like:
|
||||
|
||||
```text
|
||||
[API] [INFO] [main.go:main:27] [17.03.26 14:05:09] service started
|
||||
2026-03-17T14:05:09+03:00 info API: service started
|
||||
```
|
||||
|
||||
The traceback field is included only when `PrintTraceback(true)` is enabled.
|
||||
Use `SetFormatter` on a writer to customize timestamps, traceback fields, colors, and message layout.
|
||||
|
||||
JSON writers emit objects with this shape:
|
||||
|
||||
@@ -126,8 +124,8 @@ record reaches any writer. Replacement rules are applied in the order they are
|
||||
added.
|
||||
|
||||
```go
|
||||
logger := slog.CreateLogger().
|
||||
Level(slog.DEBUG).
|
||||
logger := sneklog.CreateLogger().
|
||||
Level(sneklog.DEBUG).
|
||||
AddReplacer("SOME_SECRET", "<redacted>").
|
||||
AddReplacer("user@example.com", "<email>")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user