Move slogd to other repository
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 35s

- Cleanup dependency imports

Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
This commit is contained in:
Jan Tytgat
2025-04-16 21:05:48 +02:00
parent 624e329778
commit bdd87d8b59
10 changed files with 21 additions and 265 deletions

View File

@ -6,8 +6,9 @@ import (
"github.com/spf13/cobra"
"git.flexabyte.io/flexabyte/go-slogd/pkg/slogd"
"git.flexabyte.io/flexabyte/go-kit/pkg/application"
"git.flexabyte.io/flexabyte/go-kit/pkg/slogd"
)
func main() {

9
go.mod
View File

@ -1,12 +1,12 @@
module git.flexabyte.io/flexabyte/go-kit
go 1.24.1
go 1.24.2
require (
git.flexabyte.io/flexabyte/go-slogd v0.0.0-20250416190113-64c1cac4d274
github.com/charmbracelet/lipgloss v1.1.0
github.com/samber/slog-formatter v1.2.0
github.com/samber/slog-multi v1.4.0
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.6
)
require (
@ -22,7 +22,8 @@ require (
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/samber/lo v1.49.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/samber/slog-formatter v1.2.0 // indirect
github.com/samber/slog-multi v1.4.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect

21
go.sum
View File

@ -1,20 +1,20 @@
git.flexabyte.io/flexabyte/go-slogd v0.0.0-20250416190113-64c1cac4d274 h1:aR9nV87ivzOTdUiGJSRry0XxegEVkiPPUx5NPz7YD3U=
git.flexabyte.io/flexabyte/go-slogd v0.0.0-20250416190113-64c1cac4d274/go.mod h1:rL08OHw4aycfjkZOS8pBfLapeG3IZHxIInW29hVVSrI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
github.com/charmbracelet/colorprofile v0.3.0 h1:KtLh9uuu1RCt+Hml4s6Hz+kB1PfV3wi++1h5ia65yKQ=
github.com/charmbracelet/colorprofile v0.3.0/go.mod h1:oHJ340RS2nmG1zRGPmhJKJ/jf4FPNNk0P39/wBPA1G0=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
@ -25,6 +25,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
@ -33,24 +35,23 @@ github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
github.com/samber/slog-formatter v1.2.0 h1:gTSHm4CxyySyhcxRkzk21CSKbGCdZVipbRMhINkNtQU=
github.com/samber/slog-formatter v1.2.0/go.mod h1:hgjhSd5Vf69XCOnVp0UW0QHCxJ8iDEm/qASjji6FNoI=
github.com/samber/slog-multi v1.3.3 h1:qhFXaYdW73FIWLt8SrXMXfPwY58NpluzKDwRdPvhWWY=
github.com/samber/slog-multi v1.3.3/go.mod h1:ACuZ5B6heK57TfMVkVknN2UZHoFfjCwRxR0Q2OXKHlo=
github.com/samber/slog-multi v1.4.0 h1:pwlPMIE7PrbTHQyKWDU+RIoxP1+HKTNOujk3/kdkbdg=
github.com/samber/slog-multi v1.4.0/go.mod h1:FsQ4Uv2L+E/8TZt+/BVgYZ1LoDWCbfCU21wVIoMMrO8=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -10,7 +10,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"git.flexabyte.io/flexabyte/go-kit/pkg/slogd"
"git.flexabyte.io/flexabyte/go-slogd/pkg/slogd"
"git.flexabyte.io/flexabyte/go-kit/pkg/slogd_colored"
)

View File

@ -1,32 +0,0 @@
package slogd
import (
"context"
"log/slog"
)
func newDisabledHandler() slog.Handler {
return &disabledHandler{}
}
func registerDisabledHandler(activate bool) {
RegisterSink(handlerDisabled, newDisabledHandler(), activate)
}
type disabledHandler struct{}
func (h *disabledHandler) Handle(ctx context.Context, r slog.Record) error {
return nil
}
func (h *disabledHandler) Enabled(ctx context.Context, level slog.Level) bool {
return false
}
func (h *disabledHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return h
}
func (h *disabledHandler) WithGroup(group string) slog.Handler {
return h
}

View File

@ -1,10 +0,0 @@
package slogd
import (
"io"
"log/slog"
)
func RegisterJSONHandler(w io.Writer, activate bool) {
RegisterSink(HandlerJSON, slog.NewJSONHandler(w, HandlerOptions()), activate)
}

View File

@ -1,56 +0,0 @@
package slogd
import (
"log/slog"
"strings"
)
const (
LevelTrace = slog.Level(-8)
LevelDebug = slog.LevelDebug
LevelInfo = slog.LevelInfo
LevelNotice = slog.Level(2)
LevelWarn = slog.LevelWarn
LevelError = slog.LevelError
LevelFatal = slog.Level(12)
LevelDefault = LevelInfo
)
var levelNames = map[slog.Leveler]string{
LevelTrace: "TRACE",
LevelDebug: "DEBUG",
LevelInfo: "INFO",
LevelNotice: "NOTICE",
LevelWarn: "WARN",
LevelError: "ERROR",
LevelFatal: "FATAL",
}
func ReplaceAttrs(groups []string, a slog.Attr) slog.Attr {
if a.Key == slog.LevelKey {
a.Value = slog.StringValue(LevelName(a.Value.Any().(slog.Level)))
}
return a
}
func Level(l string) slog.Level {
mux.Lock()
defer mux.Unlock()
for k, v := range levelNames {
if strings.ToUpper(l) == v {
return k.Level()
}
}
return LevelDefault
}
func LevelName(l slog.Level) string {
mux.Lock()
defer mux.Unlock()
for k, v := range levelNames {
if k == l {
return v
}
}
return levelNames[LevelDefault]
}

View File

@ -1,140 +0,0 @@
package slogd
import (
"context"
"log/slog"
"sync"
slogformatter "github.com/samber/slog-formatter"
slogmulti "github.com/samber/slog-multi"
)
const (
HandlerText string = "text"
HandlerJSON string = "json"
handlerDisabled string = "disabled"
)
const (
FlowFanOut Flow = iota
FlowPipeline
FlowRouting
FlowFailOver
FlowLoadBalancing
)
type Flow int
var (
ctxKey = contextKey{}
)
var (
handlers = make(map[string]slog.Handler)
activeHandler string
level = new(slog.LevelVar)
formatters []slogformatter.Formatter
middlewares []slogmulti.Middleware
source bool
logger *slog.Logger
mux = &sync.Mutex{}
)
func ActiveHandler() string {
mux.Lock()
defer mux.Unlock()
return activeHandler
}
func Key() contextKey {
return ctxKey
}
func Disable() {
UseHandler(handlerDisabled)
}
func FromContext(ctx context.Context) *slog.Logger {
if l, ok := ctx.Value(Key()).(*slog.Logger); ok {
return l
}
return Logger()
}
func HandlerOptions() *slog.HandlerOptions {
return &slog.HandlerOptions{
AddSource: source,
Level: level,
ReplaceAttr: ReplaceAttrs,
}
}
func Init(l slog.Level, addSource bool) {
level.Set(l)
source = addSource
}
func Logger() *slog.Logger {
mux.Lock()
defer mux.Unlock()
if logger == nil {
logger = slog.New(handlers[handlerDisabled])
}
return logger
}
func SetLevel(l slog.Level) {
mux.Lock()
defer mux.Unlock()
level.Set(l)
}
func RegisterFormatter(f slogformatter.Formatter) {
mux.Lock()
defer mux.Unlock()
formatters = append(formatters, f)
}
func RegisterMiddleware(h slogmulti.Middleware) {
mux.Lock()
defer mux.Unlock()
middlewares = append(middlewares, h)
}
func RegisterSink(name string, h slog.Handler, activate bool) {
mux.Lock()
handlers[name] = h
mux.Unlock()
if activate {
UseHandler(name)
}
}
func UseHandler(name string) {
mux.Lock()
defer mux.Unlock()
if _, ok := handlers[name]; !ok {
Logger().LogAttrs(context.Background(), LevelError, "could not find handler", slog.String("name", name))
return
}
formatterPipe := slogformatter.NewFormatterMiddleware(formatters...)
pipe := slogmulti.Pipe(middlewares...).Pipe(formatterPipe)
handler := slogmulti.Fanout(handlers[name])
logger = slog.New(pipe.Handler(handler))
activeHandler = name
}
func WithContext(ctx context.Context) context.Context {
return context.WithValue(ctx, Key(), Logger())
}
func init() {
// RegisterFormatter(LevelFormatter())
// RegisterMiddleware(NewLevelMiddleware())
registerDisabledHandler(true)
}
type contextKey struct{}

View File

@ -1,10 +0,0 @@
package slogd
import (
"io"
"log/slog"
)
func RegisterTextHandler(w io.Writer, activate bool) {
RegisterSink(HandlerText, slog.NewTextHandler(w, HandlerOptions()), activate)
}

View File

@ -10,7 +10,7 @@ import (
"github.com/charmbracelet/lipgloss"
"git.flexabyte.io/flexabyte/go-kit/pkg/slogd"
"git.flexabyte.io/flexabyte/go-slogd/pkg/slogd"
)
const (