stdlog

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2025 License: ISC Imports: 6 Imported by: 0

Documentation

Overview

Package heavyhitter registers two endpoints, /debug/logs/on and /debug/logs/off, as a side-effect. When /debug/logs/on is called, the log level of Handler is set to debug. When /debug/logs/off is called, the log level of Handler is set to info.

Index

Constants

This section is empty.

Variables

View Source
var HTTPErrorLog = slog.NewLogLogger(newFilterHandler(
	Handler.WithAttrs(
		[]slog.Attr{slog.String("via", "http.Server.ErrorLog")},
	),
	func(r slog.Record) bool {

		if Handler.Enabled(context.Background(), slog.LevelDebug) {
			return true
		}
		if strings.HasPrefix(r.Message, "http: TLS handshake error") {

			return strings.Contains(r.Message, "acme/autocert") &&
				!strings.HasSuffix(r.Message, "missing server name") &&
				!strings.HasSuffix(r.Message, "not configured in HostWhitelist") &&
				!strings.HasSuffix(r.Message, "server name contains invalid character") &&
				!strings.HasSuffix(r.Message, "server name component count invalid")
		}
		if strings.HasPrefix(r.Message, "http2: server: error reading preface from client") {
			return !strings.HasSuffix(r.Message, "read: connection reset by peer")
		}
		return true
	},
), slog.LevelWarn)

HTTPErrorLog is a log.Logger to be used as a http.Server.ErrorLog. It logs at the WARN level, filtering out common background noise unless debug logging is enabled.

View Source
var Handler = multiHandler([]slog.Handler{
	slog.Handler(slog.NewJSONHandler(os.Stdout,
		&slog.HandlerOptions{AddSource: true, Level: logLevel})),
	slog.Handler(slog.NewTextHandler(os.Stderr,
		&slog.HandlerOptions{Level: logLevel})),
})

Handler is a multi-handler that writes human-readable logs to stdout and machine-readable logs to stderr.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL