Documentation
¶
Index ¶
- Constants
- func ColorProfileFromContext(ctx context.Context) termenv.Profile
- func ContextWithColorMode(ctx context.Context, noColor bool) context.Context
- func ContextWithDebugMode(ctx context.Context, debug bool) context.Context
- func Debug(msg string, args ...any)
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorContext(ctx context.Context, msg string, args ...any)
- func ExtraDebug(msg string, args ...any)
- func ExtraDebugContext(ctx context.Context, msg string, args ...any)
- func Info(msg string, args ...any)
- func InfoContext(ctx context.Context, msg string, args ...any)
- func IsDebug(ctx context.Context) bool
- func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) *slog.JSONHandler
- func NewTextHandler(w io.Writer, opts *slog.HandlerOptions) *slog.TextHandler
- func SetDefault(l *Logger)
- func Trace(msg string, args ...any)
- func TraceContext(ctx context.Context, msg string, args ...any)
- func Warn(msg string, args ...any)
- func WarnContext(ctx context.Context, msg string, args ...any)
- func WithLogger(ctx context.Context, logger *Logger) context.Context
- type HandlerOptions
- type Level
- type LineWriter
- type Logger
- func Default() *Logger
- func FromContext(ctx context.Context) *Logger
- func GlobalLogger(ctx context.Context, name string, attrs ...log.KeyValue) *Logger
- func New(h slog.Handler) *Logger
- func PrettyLogger(dest io.Writer, profile termenv.Profile, level slog.Level) *Logger
- func SpanLogger(ctx context.Context, name string, attrs ...log.KeyValue) *Logger
- func With(args ...any) *Logger
- func (l *Logger) ExtraDebug(msg string, args ...any)
- func (l *Logger) ExtraDebugContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Trace(msg string, args ...any)
- func (l *Logger) TraceContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) With(args ...any) *Logger
- type Writer
Constants ¶
const ( // standard levels LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError // LevelExtraDebug is between Debug and Trace. It had extra information that's useful sometimes // but not as overwhelming as Trace. e.g. OTel logging is at this level. LevelExtraDebug = slog.LevelDebug - 1 // Trace is the most verbose level. It includes session logging and an enormous amount of detail from // buildkit on cache refs and cache queries. LevelTrace = slog.LevelDebug - 2 )
Variables ¶
This section is empty.
Functions ¶
func ColorProfileFromContext ¶ added in v0.19.6
OutputWithContextColorMode returns a termenv.Output configured according to the given context's OpenTelemetry baggage.
func ContextWithColorMode ¶ added in v0.11.7
ContextWithColorMode enables or disables color mode in the given context's OpenTelemetry baggage.
func ContextWithDebugMode ¶ added in v0.11.7
ContextWithDebugMode enables or disables debug mode in the given context's OpenTelemetry baggage.
func ExtraDebug ¶
func NewJSONHandler ¶
func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) *slog.JSONHandler
func NewTextHandler ¶
func NewTextHandler(w io.Writer, opts *slog.HandlerOptions) *slog.TextHandler
func SetDefault ¶
func SetDefault(l *Logger)
Types ¶
type HandlerOptions ¶ added in v0.19.11
type HandlerOptions = slog.HandlerOptions
type LineWriter ¶ added in v0.19.11
type LineWriter struct {
// contains filtered or unexported fields
}
LineWriter wraps a Logger and writes each line as a log message at the specified level. It buffers partial lines until a newline is received.
func NewLineWriter ¶ added in v0.19.11
func NewLineWriter(logger *Logger, level Level) *LineWriter
NewLineWriter creates an io.Writer that logs each line at the specified level.
type Logger ¶
Logger wraps the slog.Logger type with support for a few additional levels
func FromContext ¶ added in v0.19.11
FromContext returns the Logger stored in the context, or the default logger if none is set.
func GlobalLogger ¶ added in v0.19.1
GlobalLogger returns a Logger that sends logs to the global span, or the current span if none is configured.
func PrettyLogger ¶ added in v0.11.7
func SpanLogger ¶ added in v0.11.7
SpanLogger returns a Logger that writes to the give context's span logs.
The logger will use the context's baggage to determine the log level and color profile:
- If no-color=true is set in baggage, the profile will be Ascii. Otherwise, it will be ANSI.
- If debug=true is set in baggage, the log level will be Debug. Otherwise, it will be Info.
func (*Logger) ExtraDebug ¶
func (*Logger) ExtraDebugContext ¶
func (*Logger) TraceContext ¶
type Writer ¶
type Writer struct {
// SyncWarn makes Write wait for lines at WARN level or worse.
SyncWarn bool
// contains filtered or unexported fields
}
Writer queues log output for a shared destination (usually stderr) and writes it from one background goroutine, so goroutines that log at the same time do not each wait for every other goroutine's write(2).
Bytes reach the destination in the order Write calls queued them. Each Write is queued whole, so a log line is never split or interleaved with another line written through the Writer. Queued bytes, including the batch being written, are bounded by limit (a single larger line is let through alone): Write blocks while the queue is full, so a destination that cannot keep up slows callers down instead of losing output.
Write returns once its bytes are queued, except for lines whose level is WARN or worse when SyncWarn is set; those wait until they are written, as with a plain locked writer. Flush waits too. A destination write error loses the rest of that batch, as a failed direct write loses its line; callers waiting on those bytes get the error and the count of their bytes that were written.
A Writer runs one goroutine for the life of the process and has no Close: it is meant for the process's own log output.