Documentation
¶
Overview ¶
Package ulog provides a configurable logging system based on Go's slog package. It follows the log structure from PHP Symfony monolog package.
Index ¶
- func New(config Config) slog.Handler
- func NewFileLogger(path string, format string, channel string, maxSize int64, maxBackups int, ...) (slog.Handler, error)
- func NewJSONLogger(w io.Writer, channel string) slog.Handler
- func NewTextLogger(w io.Writer, channel string) slog.Handler
- func ParseByteSize(size string) (int64, error)
- func WithAttrsContext(ctx context.Context, attrs ...slog.Attr) context.Context
- type Config
- type FileWriter
- type Formatter
- type Handler
- type JSONFormatter
- type LogRecord
- type MultiHandler
- type MultiWriter
- type TextFormatter
- type Writer
- type WriterCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFileLogger ¶
func NewFileLogger(path string, format string, channel string, maxSize int64, maxBackups int, maxAge int) (slog.Handler, error)
NewFileLogger creates a new logger that writes to a file
func NewJSONLogger ¶
NewJSONLogger creates a new logger with JSON formatting
func NewTextLogger ¶
NewTextLogger creates a new logger with text formatting
func ParseByteSize ¶
Types ¶
type Config ¶
type Config struct {
Formatter Formatter
Writer io.Writer
Channel string
CtxKeyName string
AddSource bool
Level slog.Level
}
Config holds the configuration for the ulog handler
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a default configuration with text formatter and os.Stderr output
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter is a writer that writes to a file with optional rotation
func NewFileWriter ¶
NewFileWriter creates a new FileWriter
func (*FileWriter) Close ¶
func (w *FileWriter) Close() error
Close implements the io.Closer interface
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements slog.Handler interface
type JSONFormatter ¶
type JSONFormatter struct {
TimeFormat string
}
JSONFormatter formats logs as JSON following Symfony monolog format
func NewJSONFormatter ¶
func NewJSONFormatter() *JSONFormatter
NewJSONFormatter creates a new JSONFormatter
type LogRecord ¶
type LogRecord struct {
Message string `json:"message"`
Channel string `json:"channel"`
Level int `json:"level"`
LevelName string `json:"level_name"`
DateTime time.Time `json:"datetime"`
Context map[string]interface{} `json:"context"`
Extra map[string]interface{} `json:"extra"`
}
LogRecord represents a log entry following the Symfony monolog structure
type MultiHandler ¶
type MultiHandler struct {
// contains filtered or unexported fields
}
MultiHandler sends log entries to multiple handlers
func NewMultiHandler ¶
func NewMultiHandler(handlers ...slog.Handler) *MultiHandler
func (*MultiHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level.
type MultiWriter ¶
type MultiWriter struct {
// contains filtered or unexported fields
}
MultiWriter wraps multiple io.Writers into a single Writer
func NewMultiWriter ¶
func NewMultiWriter(writers ...io.Writer) *MultiWriter
NewMultiWriter creates a new MultiWriter with the provided writers
func (*MultiWriter) AddWriter ¶
func (mw *MultiWriter) AddWriter(w io.Writer)
AddWriter adds a new writer to the MultiWriter
type TextFormatter ¶
type TextFormatter struct {
TimeFormat string
}
TextFormatter formats logs as human-readable text
func NewTextFormatter ¶
func NewTextFormatter() *TextFormatter
NewTextFormatter creates a new TextFormatter
type WriterCloser ¶
type WriterCloser struct {
// contains filtered or unexported fields
}
WriterCloser is a simple implementation of Writer that wraps an io.Writer
func NewWriterCloser ¶
func NewWriterCloser(w io.Writer) *WriterCloser
NewWriterCloser creates a new WriterCloser
func (*WriterCloser) Close ¶
func (w *WriterCloser) Close() error
Close implements the io.Closer interface