log

package
v1.0.0-beta24 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

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 Field

type Field struct {
	Key   string
	Value any
}

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 Formatter

type Formatter interface {
	Format(rec *Record) []byte
}

type Level

type Level uint8
const (
	LevelDebug Level = iota
	LevelInfo
	LevelSuccess
	LevelWarn
	LevelError
	LevelFatal
	// LevelOff disables all log output. Used by Nop().
	LevelOff
)

func (Level) Color

func (l Level) Color() string

func (Level) Icon

func (l Level) Icon() string

func (Level) Tag

func (l Level) Tag() string

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 Default

func Default() *Logger

Default returns a Logger with DefaultConfig().

func New

func New(cfg Config) *Logger

New creates a Logger from the given Config. It wires a TextFormatter and ConsoleWriter whose settings mirror the Config flags.

func NewWithWriter

func NewWithWriter(cfg Config, w Writer) *Logger

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) Debug

func (l *Logger) Debug(msg string, kvs ...any)

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

func (*Logger) Debugln

func (l *Logger) Debugln(args ...any)

func (*Logger) Error

func (l *Logger) Error(msg string, kvs ...any)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

func (*Logger) Errorln

func (l *Logger) Errorln(args ...any)

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, kvs ...any)

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...any)

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...any)

func (*Logger) Info

func (l *Logger) Info(msg string, kvs ...any)

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

func (*Logger) Infoln

func (l *Logger) Infoln(args ...any)

func (*Logger) Printf

func (l *Logger) Printf(format string, args ...any)

func (*Logger) Println

func (l *Logger) Println(args ...any)

func (*Logger) Success

func (l *Logger) Success(msg string, kvs ...any)

func (*Logger) Successf

func (l *Logger) Successf(format string, args ...any)

func (*Logger) Successln

func (l *Logger) Successln(args ...any)

func (*Logger) Warn

func (l *Logger) Warn(msg string, kvs ...any)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

func (*Logger) Warnln

func (l *Logger) Warnln(args ...any)

func (*Logger) WithModule

func (l *Logger) WithModule(name string) *Logger

WithModule returns a child Logger that tags every record with the given module name. The child shares the same Writer and Formatter.

func (*Logger) ZapLogger

func (l *Logger) ZapLogger() *zap.Logger

ZapLogger returns a *zap.Logger that routes all gotd internal logs through this Logger instance, replacing JSON output with styled text.

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 Record

type Record struct {
	Level   Level
	Message string
	Time    time.Time
	Module  string
	File    string
	Line    int
	Func    string
	Fields  []Field
}

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

type TextFormatter struct {
	Color      bool
	Timestamp  bool
	TimeLayout string
	Caller     bool
	FuncName   bool
}

func NewTextFormatter

func NewTextFormatter() *TextFormatter

func (*TextFormatter) Format

func (f *TextFormatter) Format(rec *Record) []byte

type Writer

type Writer interface {
	Write(data []byte) error
	Close() error
}

Jump to

Keyboard shortcuts

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