FILE / ScuroNeko/SNekLog
RELEASE_NOTES.md
Исходный файл и его история в репозитории.
- 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
4.9 KiB
4.9 KiB
v2.0.0
Highlights
- Renamed the public Go package from
slogtosneklogto avoid confusion with the standard librarylog/slogpackage. - Moved the module path to
git.scuroneko.dev/scuroneko/slog/v2for Go module major-version compatibility. - Replaced fixed text writer settings with formatter-based output customization.
- Added built-in ANSI color support and removed the external
github.com/fatih/colordependency tree. - Formatters: a new way do display your logs!
Breaking Changes
- Import paths must use the
/v2module suffix:
import sneklog "git.scuroneko.dev/scuroneko/slog/v2"
- Package references should use
snekloginstead ofslog. - Removed
Logger.PrintTimeandLogger.PrintTraceback; configure output through writer formatters instead. - Changed text writer constructors:
CreateTextWriter(w, printTraceback, printTime)is nowCreateTextWriter(w).CreateTextFileWriter(path, printTraceback, printTime)is nowCreateTextFileWriter(path).CreateTextStdoutWriter(printTraceback, printTime)is nowCreateTextStdoutWriter().
- Removed the old text formatting helpers:
BuildString,FormatTime,FormatTraceback, andFormatFullTraceback. - JSON
timevalues are now formatted through the configured formatter and stored as strings inLoggerJsonMessage.
Added
Formatterfor configurable message layouts, timestamp layouts, traceback layouts, separators, and color behavior.DefaultTextFormatterandDefaultJsonFormatterdefaults for text and JSON writers.LoggerTextWriter.SetFormatterandLoggerJsonWriter.SetFormatter.- Strftime-like timestamp format constants such as
RFC3339,Kitchen,DateTime,DateOnly, andTimeOnly. - Built-in color types and helpers:
FgColor,BgColor, andAttribute.ColorStringBuilder.- Level color getters/setters on
LogLevel.
- Tests covering formatter defaults, empty traceback placeholders, literal
%sequences in messages, color controls, and JSON newline semantics.
Changed
- Text output defaults to
DefaultTextFormatterinstead of the old hard-coded string builder. - JSON output defaults to
DefaultJsonFormatterand can now format the JSONmessagefield throughFormatter. - Newline semantics are normalized before text and JSON formatting, so trailing
\ncontrols record termination without becoming part of the message. - Text color output is enabled by default only for stdout/stderr.
- Example code now demonstrates custom formatters and color configuration.
- Go dependencies were simplified by removing:
github.com/fatih/colorgithub.com/mattn/go-colorablegithub.com/mattn/go-isattygolang.org/x/sys
Fixed
NewFormatter()now returns a fresh copy instead of mutatingDefaultTextFormatter.Formatter.FormatMessageno longer panics when called with an empty traceback.- Placeholder-looking text inside log messages, such as
%Lor%s, is preserved literally. SetColorOutput(false)disables color output.SetColorOnlyStdout(false)allows color output for non-stdout writers.
Migration
Before:
import "git.scuroneko.dev/scuroneko/slog"
logger := slog.CreateLogger().
Prefix("API").
Level(slog.DEBUG).
PrintTraceback(true)
text := logger.CreateTextStdoutWriter()
After:
import sneklog "git.scuroneko.dev/scuroneko/slog/v2"
logger := sneklog.CreateLogger().
Prefix("API").
Level(sneklog.DEBUG)
formatter := sneklog.NewFormatter().
SetFormat("%t [%L] %N: %m (%B)")
text := logger.CreateTextStdoutWriter().
SetFormatter(formatter)
v1.2.0
Highlights
- Added message replacement with
Logger.AddReplacer(old, new)for masking secrets or normalizing log output. - Preserved the existing
LoggerWriter.Print(...any)contract, so custom writers do not need a signature update. - Improved JSON writer newline handling for messages that already end with
\n.
Added
Logger.AddReplacer(old, new)appends a replacement rule that is applied before records are sent to writers.- README and package GoDoc now document message replacement and include usage examples.
- Tests covering message type preservation for custom writers, JSON empty messages, and JSON trailing newline behavior.
Fixed
LoggerJsonWriter.Printno longer panics when called with no message arguments.LoggerJsonWriter.Printnow treats a trailing newline at the end of the last message as newline semantics and does not include that newline in the JSONmessagefield.- Log messages keep their original argument types for custom writers when no replacement rules are configured.
Changed
- Updated the example program to demonstrate
AddReplacer. - Updated dependencies:
github.com/fatih/colorfromv1.18.0tov1.19.0github.com/mattn/go-isattyfromv0.0.20tov0.0.21golang.org/x/sysfromv0.42.0tov0.43.0
Compatibility
No breaking API changes are intended in this release. The public LoggerWriter interface continues to accept messages ...any.