Imports #
"errors"
"log/slog"
"time"
"context"
"fmt"
"io"
"log/slog"
"log/slog/internal/buffer"
"strconv"
"time"
"errors"
"log/slog"
"time"
"context"
"fmt"
"io"
"log/slog"
"log/slog/internal/buffer"
"strconv"
"time"
var testAttrs = []slog.Attr{...}
var testDuration = *ast.BinaryExpr
var testError = *ast.CallExpr
var testInt = 32768
const testMessage = "Test logging, but use a somewhat realistic message length."
var testString = "7e3b3b2aaeff56a7108fe11e154200dd/7819479873059528190"
var testTime = *ast.CallExpr
const wantText = "time=1651363200 level=0 msg=Test logging, but use a somewhat realistic message length. string=7e3b3b2aaeff56a7108fe11e154200dd/7819479873059528190 status=32768 duration=23000000000 time=1651363200 error=fail\n"
An asyncHandler simulates a Handler that passes Records to a background goroutine for processing. Because sending to a channel can be expensive due to locking, we simulate a lock-free queue by adding the Record to a ring buffer. Omitting the locking makes this little more than a copy of the Record, but that is a worthwhile thing to measure because Records are on the large side. Since nothing actually reads from the ring buffer, it can handle an arbitrary number of Records without either blocking or allocation.
type asyncHandler struct {
ringBuffer [100]slog.Record
next int
}
A disabledHandler's Enabled method always returns false.
type disabledHandler struct {
}
A fastTextHandler writes a Record to an io.Writer in a format similar to slog.TextHandler, but without quoting or locking. It has a few other performance-motivated shortcuts, like writing times as seconds since the epoch instead of strings. It is intended to represent a high-performance Handler that synchronously writes text (as opposed to binary).
type fastTextHandler struct {
w io.Writer
}
func (disabledHandler) Enabled(context.Context, slog.Level) bool
func (h *fastTextHandler) Enabled(context.Context, slog.Level) bool
func (*asyncHandler) Enabled(context.Context, slog.Level) bool
func (h *fastTextHandler) Handle(_ context.Context, r slog.Record) error
func (disabledHandler) Handle(context.Context, slog.Record) error
func (h *asyncHandler) Handle(_ context.Context, r slog.Record) error
func (*asyncHandler) WithAttrs([]slog.Attr) slog.Handler
func (h *fastTextHandler) WithAttrs([]slog.Attr) slog.Handler
func (disabledHandler) WithAttrs([]slog.Attr) slog.Handler
func (*fastTextHandler) WithGroup(string) slog.Handler
func (*asyncHandler) WithGroup(string) slog.Handler
func (disabledHandler) WithGroup(string) slog.Handler
func (h *fastTextHandler) appendTime(buf *buffer.Buffer, t time.Time)
func (h *fastTextHandler) appendValue(buf *buffer.Buffer, v slog.Value)
func newAsyncHandler() *asyncHandler
func newFastTextHandler(w io.Writer) slog.Handler
Generated with Arrow