Documentation
¶
Index ¶
- type Config
- type ConsoleWriter
- type Field
- type FileWriter
- type Formatter
- type Level
- type Logger
- func (l *Logger) Debug(msg string, kvs ...any)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Debugln(args ...any)
- func (l *Logger) Error(msg string, kvs ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Errorln(args ...any)
- func (l *Logger) Fatal(msg string, kvs ...any)
- func (l *Logger) Fatalf(format string, args ...any)
- func (l *Logger) Fatalln(args ...any)
- func (l *Logger) Info(msg string, kvs ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Infoln(args ...any)
- func (l *Logger) Printf(format string, args ...any)
- func (l *Logger) Println(args ...any)
- func (l *Logger) Success(msg string, kvs ...any)
- func (l *Logger) Successf(format string, args ...any)
- func (l *Logger) Successln(args ...any)
- func (l *Logger) Warn(msg string, kvs ...any)
- func (l *Logger) Warnf(format string, args ...any)
- func (l *Logger) Warnln(args ...any)
- func (l *Logger) WithModule(name string) *Logger
- func (l *Logger) ZapLogger() *zap.Logger
- type MultiWriter
- type Record
- type RotatingFileWriter
- type TextFormatter
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MinLevel is the minimum severity to emit. Messages below this are discarded.
MinLevel Level
// Debug enables debug-level output (convenience alias for MinLevel = LevelDebug).
Debug bool
// Timestamp enables time prefix on each log line.
Timestamp bool
// Color enables ANSI color output. Disable for file/structured output.
Color bool
// Caller appends file:line to log lines.
Caller bool
// FuncName appends the function name alongside caller info.
FuncName bool
// Module sets a default module tag (e.g. "dispatcher", "adapter").
Module string
// LogFile enables file logging. When set, logs go to both console and
// this file path. File output is always plain text (no ANSI colors).
LogFile string
// RotateMaxSize enables log rotation when > 0. Bytes per file before rotating.
RotateMaxSize int64
// RotateMaxBackups is the number of rotated files to keep (default 3).
RotateMaxBackups int
}
Config controls logger behavior.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config suitable for development.
type ConsoleWriter ¶
type ConsoleWriter struct {
// contains filtered or unexported fields
}
func NewConsoleWriter ¶
func NewConsoleWriter() *ConsoleWriter
func (*ConsoleWriter) Close ¶
func (w *ConsoleWriter) Close() error
func (*ConsoleWriter) Write ¶
func (w *ConsoleWriter) Write(data []byte) error
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
func NewFileWriter ¶
func NewFileWriter(path string) (*FileWriter, error)
func (*FileWriter) Close ¶
func (w *FileWriter) Close() error
func (*FileWriter) Write ¶
func (w *FileWriter) Write(data []byte) error
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the core logging type. It is safe for concurrent use because thread-safety is handled by the underlying Writer.
func New ¶
New creates a Logger from the given Config. It wires a TextFormatter and ConsoleWriter whose settings mirror the Config flags.
func NewWithWriter ¶
NewWithWriter is like New but lets the caller supply a custom Writer (e.g. FileWriter, MultiWriter).
func Nop ¶
func Nop() *Logger
Nop returns a Logger that discards all output. Used when no LogConfig is provided.
func (*Logger) WithModule ¶
WithModule returns a child Logger that tags every record with the given module name. The child shares the same Writer and Formatter.
type MultiWriter ¶
type MultiWriter struct {
// contains filtered or unexported fields
}
func NewMultiWriter ¶
func NewMultiWriter(writers ...Writer) *MultiWriter
func (*MultiWriter) Close ¶
func (mw *MultiWriter) Close() error
func (*MultiWriter) Write ¶
func (mw *MultiWriter) Write(data []byte) error
type RotatingFileWriter ¶
type RotatingFileWriter struct {
// contains filtered or unexported fields
}
RotatingFileWriter wraps file writing with automatic size-based rotation.
func NewRotatingFileWriter ¶
func NewRotatingFileWriter(path string, maxSize int64, maxBackups int) (*RotatingFileWriter, error)
func (*RotatingFileWriter) Close ¶
func (w *RotatingFileWriter) Close() error
func (*RotatingFileWriter) Write ¶
func (w *RotatingFileWriter) Write(data []byte) error
type TextFormatter ¶
func NewTextFormatter ¶
func NewTextFormatter() *TextFormatter
func (*TextFormatter) Format ¶
func (f *TextFormatter) Format(rec *Record) []byte