(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
+19 -11
View File
@@ -2,16 +2,21 @@ package main
import (
"bytes"
"fmt"
"git.scuroneko.dev/scuroneko/sneklog/v2"
)
func main() {
logger := sneklog.CreateLogger().
Prefix("EXAMPLE").
Level(sneklog.DEBUG).
JsonPretty(true).
httpGet := sneklog.NewLogLevelWithColors(0, "get", sneklog.FgGreen, sneklog.BgNone)
httpPost := sneklog.NewLogLevelWithColors(0, "post", sneklog.FgBlue, sneklog.BgNone)
httpDelete := sneklog.NewLogLevel(0, "delete")
httpDelete.SetBackgroundRGB(128, 0, 0)
httpDelete.AddAttribute(sneklog.Italic).AddAttribute(sneklog.Bold)
logger := sneklog.NewLogger().
SetName("EXAMPLE").
SetLevel(sneklog.DEBUG).
SetJSONPretty(true).
AddReplacer("SOME_SECRET", "<Secret>")
sneklog.INFO.SetBgColor(sneklog.BgBlue).SetFgColor(sneklog.FgWhite)
@@ -20,13 +25,13 @@ func main() {
jsonStdout := logger.CreateJsonStdoutWriter()
formatter := sneklog.NewFormatter().
SetFormat("[%t] [%L] [%N]: %m (%S)").
SetFormat("[%t] [%L] [%N]: %m (%s)").
SetTimeStampFormat(sneklog.Kitchen).
SetTraceBackFormat("%s %f:%n %p")
jsonFormatter := sneklog.NewFormatter().
SetFormat("[%L] [%N] %m").
SetColorOutput(true).
SetColorOutput(false).
SetTimeStampFormat(sneklog.Kitchen)
textStdout.SetFormatter(formatter)
@@ -62,19 +67,22 @@ func main() {
logger.Errorln("request failed")
logger.Debugln("debug details")
logger.Infoln("sensitive info, SOME_SECRET")
logger.Println(httpGet, "this can be logging of http get request/response...")
logger.Println(httpPost, "...and this can be logging of http post request/response...")
logger.Println(httpDelete, "...but this logging of http delete request/response with highly customizable level!")
if err := logger.Close(); err != nil {
panic(err)
}
s := sneklog.NewColorStringBuilder().
AddColorRgbBg(31, 41, 40).
AddColorRgbFg(220, 215, 186).
AddBackgroundRGB(sneklog.NewBgColorRGB(31, 41, 40)).
AddForegroundRGB(sneklog.NewFgColorRGB(220, 215, 186)).
AddAttribute(sneklog.Italic).AddAttribute(sneklog.Bold).
AddText("Some Very very very cool stuff, themed in Kanagawa colors!").String()
println(s)
fmt.Println("external buffer contents:")
fmt.Println(externalBuffer.String())
//fmt.Println("external buffer contents:")
//fmt.Println(externalBuffer.String())
}