Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] slog handler #5195

Closed
wants to merge 34 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6ca9499
[WIP] Initial slog handler
MrAlias Mar 1, 2024
5c87e5c
Add benchmarks
MrAlias Mar 2, 2024
a1ef4ba
Fix BenchmarkHandler
MrAlias Mar 5, 2024
e7cf39d
Use noop LoggerProvider in bench
MrAlias Mar 6, 2024
bcbc27b
Flatten convertLevel
MrAlias Mar 6, 2024
78152cc
Update bench of Handle only using WithGroup.WithAttrs
MrAlias Mar 7, 2024
582b806
Zero alloc Handle when holding attr and group
MrAlias Mar 7, 2024
b6d70f6
Add the kvBuffer type
MrAlias Mar 8, 2024
2dca61f
Add kvBuffer KeyValue and flatten convertAttr
MrAlias Mar 11, 2024
7dbf476
Remove TODO
MrAlias Mar 11, 2024
c84abb5
Simplify testing loggerProvider
MrAlias Mar 11, 2024
3a7c1db
Copy slogtest testing harness and expand
MrAlias Mar 11, 2024
b9f412a
Add test for value conversion
MrAlias Mar 11, 2024
c5767c6
Remove unused code from group.KeyValue
MrAlias Mar 11, 2024
4494e44
Remove unneeded kvBuffer.Clone
MrAlias Mar 11, 2024
6af7f4b
Remove empty check from WithAttrs and WithGroup
MrAlias Mar 11, 2024
abd29c2
Ensure isolation of WithAttr
MrAlias Mar 11, 2024
be01506
Run slogtest.TestHandler instead of copying
MrAlias Mar 11, 2024
fa6eefd
Remove value2Str
MrAlias Mar 11, 2024
0c5ce80
Comment source of code copied from slogtest.
MrAlias Mar 11, 2024
6340c3c
Comment code
MrAlias Mar 11, 2024
2b77982
Fix lint
MrAlias Mar 11, 2024
cebb87f
Expand group comment
MrAlias Mar 11, 2024
2e13353
Add concurrency test
MrAlias Mar 12, 2024
9ce4320
Return string attr for unrecognized kind
MrAlias Mar 12, 2024
08e1bfd
Document nil lp to New
MrAlias Mar 12, 2024
3084e0d
Use default noop for nil in New within tests
MrAlias Mar 12, 2024
5652789
Add link to inspiration for buffer size limit
MrAlias Mar 12, 2024
20f6c0e
Update bridges/sloghandler/handler_test.go
MrAlias Mar 12, 2024
40b9b00
Use pkg name from source as scope by default
MrAlias Mar 12, 2024
4bc7625
Accept a Logger instead of a LoggerProvider
MrAlias Mar 14, 2024
6b4c3c3
Apply feedback: accept a LoggerProvider
MrAlias Mar 14, 2024
5fe15aa
Add Version func
MrAlias Mar 14, 2024
20ce015
Merge branch 'main' into sloghandler
MrAlias Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bridges/sloghandler/handler_test.go
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log/slog"
"reflect"
"runtime"
"sync"
"testing"
"testing/slogtest"
"time"
Expand Down Expand Up @@ -387,6 +388,31 @@ func value2Result(v log.Value) any {
return nil
}

func TestConcurrentSafety(t *testing.T) {
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
lp := noop.NewLoggerProvider()
h := sloghandler.New(lp)

const goroutineN = 10

var wg sync.WaitGroup
wg.Add(goroutineN)

for i := 0; i < goroutineN; i++ {
go func() {
defer wg.Done()

_ = h.Enabled(context.Background(), slog.LevelDebug)

r := slog.NewRecord(time.Now(), slog.LevelDebug, "msg", 0)
_ = h.Handle(context.Background(), r)

_ = h.WithAttrs([]slog.Attr{slog.Any("key", nil)})
_ = h.WithGroup("name")
}()
}
wg.Wait()
}

func BenchmarkHandler(b *testing.B) {
var (
h slog.Handler
Expand Down
Loading