wlog

package
v0.0.0-...-dd4be11 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package wlog provides colorized logging utilities for HTTP requests and responses.

Index

Constants

This section is empty.

Variables

View Source
var (
	// RED is the ANSI escape code for red text.
	RED = "\u001b[31m"
	// BLUE is the ANSI escape code for green text.
	BLUE = "\u001b[32m"
	// YELLOW is the ANSI escape code for yellow text.
	YELLOW = "\u001b[33m"
	// ORANGE is the ANSI escape code for cyan text.
	ORANGE = "\u001b[36m"
	// RESET is the ANSI escape code to reset text formatting.
	RESET = "\u001B[0m"
)
View Source
var (
	// StackSourceFileName is the key for the source file name in stack traces.
	StackSourceFileName = "source"
	// StackSourceLineName is the key for the line number in stack traces.
	StackSourceLineName = "line"
	// StackSourceFunctionName is the key for the function name in stack traces.
	StackSourceFunctionName = "func"
)

Functions

func ColorStatus

func ColorStatus(status int) string

ColorStatus returns an HTTP status code string with color formatting based on the status value.

func ColorTime

func ColorTime(dur time.Duration) string

ColorTime returns a duration string with color formatting based on the duration length.

func FromContext

func FromContext(ctx context.Context) *zerolog.Logger

FromContext extracts a logger from the context, or returns the global logger.

func FromContextOk

func FromContextOk(ctx context.Context) (*zerolog.Logger, bool)

FromContextOk extracts a logger from the context and returns whether it was present.

func GlobalLogger

func GlobalLogger() *zerolog.Logger

GlobalLogger returns a copy of the global logger instance. The returned logger is safe to use concurrently and can have UpdateContext called on it without racing with other goroutines.

func MarshalStack

func MarshalStack(err error) any

MarshalStack extracts and marshals the stack trace from an error.

func NewZeroLogger

func NewZeroLogger(opts ...CreateOpts) *zerolog.Logger

NewZeroLogger creates a new zerolog logger with the given options.

func NopLogger

func NopLogger() zerolog.Logger

NopLogger returns a no-op logger that discards all log messages.

func PrintStackTrace

func PrintStackTrace()

PrintStackTrace captures and prints the current stack trace.

func RouteColor

func RouteColor(r *http.Request) string

RouteColor returns the route pattern for the request, highlighting unknown routes in red.

func SetLogLevel

func SetLogLevel(level zerolog.Level)

SetLogLevel sets the global log level.

func ShowStackTrace

func ShowStackTrace()

ShowStackTrace is a placeholder for stack trace visualization.

func WithContext

func WithContext(ctx context.Context, l *zerolog.Logger) context.Context

WithContext adds a logger to the context.

Types

type CreateOpts

type CreateOpts struct {
	Level   zerolog.Level
	LogFile string
	Global  bool
}

CreateOpts configures logging options.

type ErrUnwrapHook

type ErrUnwrapHook struct{}

ErrUnwrapHook is a zerolog hook for unwrapping errors.

func (ErrUnwrapHook) Run

func (h ErrUnwrapHook) Run(e *zerolog.Event, level zerolog.Level, msg string)

Run executes the hook on log events.

type WLConsoleLogger

type WLConsoleLogger struct {
	// contains filtered or unexported fields
}

WLConsoleLogger is a development console logger with colored output.

func (WLConsoleLogger) Write

func (l WLConsoleLogger) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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