Documentation
¶
Overview ¶
Package xrayslog provides utilities for interfacing with the slog package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
NewHandler returns a slog.Handler that adds trace ID to the log record.
Example ¶
package main
import (
"context"
"log/slog"
"os"
"github.com/shogo82148/aws-xray-yasdk-go/xray"
"github.com/shogo82148/aws-xray-yasdk-go/xray/xrayslog"
)
func main() {
// 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
func NewXRayLogger ¶
NewXRayLogger returns a new xraylog.Logger such that each call to its Output method dispatches a Record to the specified handler. The logger acts as a bridge from the older xraylog API to newer structured logging handlers. The log level can be set by using either the AWS_XRAY_DEBUG_MODE or AWS_XRAY_LOG_LEVEL environment variables. If AWS_XRAY_DEBUG_MODE is set, the log level is set to the debug level. AWS_XRAY_LOG_LEVEL may be set to debug, info, warn, error or silent. This value is ignored if AWS_XRAY_DEBUG_MODE is set.
func NewXRayLoggerWithMinLevel ¶ added in v1.7.1
NewXRayLoggerWithMinLevel returns a new xraylog.Logger such that each call to its Output method dispatches a Record to the specified handler. The logger acts as a bridge from the older xraylog API to newer structured logging handlers.
Types ¶
This section is empty.