Documentation
¶
Overview ¶
Package colorized provides a slog.Handler with color-coded terminal output. Use it for human-readable logs in CLI apps or development environments.
Example:
handler := colorized.NewHandler(os.Stdout, colorized.WithLevel(slog.LevelInfo))
logger := slog.New(handler)
logger.Info("started", "port", 8080)
Index ¶
- Constants
- func NewHandler(w io.Writer, opts ...Option) slog.Handler
- type Handler
- type Option
- func WithAddSource() Option
- func WithAttributeColors(v map[string][]int) Option
- func WithLevel(v slog.Leveler) Option
- func WithNoColor() Option
- func WithPrefixAttributeKey[T interface{ ... }](v T) Option
- func WithReplaceAttr(replace func(groups []string, attr slog.Attr) slog.Attr) Option
- func WithTimeFormat[T interface{ ... }](v T) Option
Constants ¶
const ( // DefaultBufferSize is the default initial buffer size (1KB). DefaultBufferSize = 1024 // DefaultMaxBufferSize is the maximum buffer size kept in pool (16KB). DefaultMaxBufferSize = 16 << 10 )
Buffer pool configuration constants.
const ( // DefaultTimeFormat is the default time format for log timestamps (RFC3339Nano). DefaultTimeFormat = time.RFC3339Nano // DefaultLogLevel is the default minimum log level (slog.LevelError). DefaultLogLevel = slog.LevelError )
const CacheShards = 16
CacheShards is the number of shards used by the time cache.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements slog.Handler with colorized terminal output. It uses lazy evaluation, lock-free caches, and buffer pooling for performance. Safe for concurrent use.
type Option ¶
type Option func(o *options)
Option is a functional option for configuring options.
func WithAttributeColors ¶
WithAttributeColors sets the attributeColors option.
func WithPrefixAttributeKey ¶
WithPrefixAttributeKey sets the prefixAttributeKey option.
func WithReplaceAttr ¶
WithReplaceAttr sets a function to transform or filter attributes before output.
func WithTimeFormat ¶
WithTimeFormat sets the timeFormat option.