Skip to content

Commit

Permalink
add an example test
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Sep 1, 2023
1 parent 8ed220c commit fb7535e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions xrayslog/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package xrayslog_test

import (
"context"
"log/slog"

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.20 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.20.7/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.16 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.16.15/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.17 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.17.13/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.19 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.19.12/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.20 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.20.7/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.17 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.17.13/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.18 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.18.10/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.16 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.16.15/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.18 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.18.10/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.19 Test on ubuntu-latest

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.19.12/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.17 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.17.13\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.16 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.16.15\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.17 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.17.13\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.16 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.16.15\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.18 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.18.10\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.19 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.19.12\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.20 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.7\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.20 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.7\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.19 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.19.12\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.18 Test on windows-latest

package log/slog is not in GOROOT (C:\hostedtoolcache\windows\go\1.18.10\x64\src\log\slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.17 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.17.13/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.18 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.18.10/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.16 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.16.15/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.19 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.19.12/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.20 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.20.7/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.16 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.16.15/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.17 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.17.13/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.18 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.18.10/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.19 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.19.12/x64/src/log/slog)

Check failure on line 5 in xrayslog/example_test.go

View workflow job for this annotation

GitHub Actions / Go 1.20 Test on macos-latest

package log/slog is not in GOROOT (/Users/runner/hostedtoolcache/go/1.20.7/x64/src/log/slog)
"os"

"github.com/shogo82148/aws-xray-yasdk-go/xray"
"github.com/shogo82148/aws-xray-yasdk-go/xrayslog"
)

func ExampleNewHandler() {
// it's for testing.
replace := func(groups []string, a slog.Attr) slog.Attr {
// Remove time.
if a.Key == slog.TimeKey && len(groups) == 0 {
return slog.Attr{}
}
return a
}

// build the logger
parent := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ReplaceAttr: replace})
h := xrayslog.NewHandler(parent, "trace_id")
logger := slog.New(h)

// begin a new segment
ctx := context.Background()
ctx, segment := xray.BeginSegmentWithHeader(ctx, "my-segment", "Root=1-5e645f3e-1dfad076a177c5ccc5de12f5")
defer segment.Close()

// output the log
logger.InfoContext(ctx, "hello")

// Output:
// level=INFO msg=hello trace_id=1-5e645f3e-1dfad076a177c5ccc5de12f5
}
1 change: 1 addition & 0 deletions xrayslog/xrayslog.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build go1.21
// +build go1.21

// Package xrayslog provides a [log/slog.Handler] that adds trace ID to the log record.
package xrayslog

import (
Expand Down

0 comments on commit fb7535e

Please sign in to comment.