cylog

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, attrs ...any)

func Debugf

func Debugf(format string, args ...any)

func Error

func Error(msg string, attrs ...any) error

func Errorf

func Errorf(format string, args ...any) error

func Info

func Info(msg string, attrs ...any)

func Infof

func Infof(format string, args ...any)

Infof 既像 fmt.Printf,又像 log/slog 一样结构化

func InitDefault

func InitDefault(opts ...Option)

InitDefault initializes the default package-level logger and updates the default configuration.

func LevelFromStr

func LevelFromStr(level string) slog.Level

func NewApacheHandler

func NewApacheHandler(w io.Writer, opts *slog.HandlerOptions) slog.Handler

func Warn

func Warn(msg string, attrs ...any)

func Warnf

func Warnf(format string, args ...any)

Types

type Config

type Config struct {
	// Filename is the file to write logs to. If empty, writes to stdout.
	Filename string
	// MaxSize is the maximum size in megabytes of the log file before it gets rotated.
	MaxSize int
	// MaxBackups is the maximum number of old log files to retain.
	MaxBackups int
	// MaxAge is the maximum number of days to retain old log files.
	MaxAge int
	// Compress determines if the rotated log files should be compressed.
	Compress bool
	// Level is the minimum level to log.
	Level slog.Level
	// Format is the log output format, "json" or "text".
	Format string
	// CallerSkip is the number of stack frames to skip to find the caller.
	CallerSkip int
	// Writer is the custom writer to write logs to.
	Writer io.Writer
	// AddSource is whether to add source information to the log.
	AddSource bool
}

Config holds the configuration for the logger.

type Logger

type Logger struct {
	*slog.Logger
}

Logger wraps the slog.Logger.

func Default

func Default() *Logger

Default returns the default logger.

func New

func New(opts ...Option) *Logger

New creates a new Logger instance with the given options.

func Skip

func Skip(skip int) *Logger

func (*Logger) Debugf

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

func (*Logger) Errorf

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

func (*Logger) Infof

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

func (*Logger) Warnf

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

type Option

type Option func(*Config)

Option defines a function that configures the logger.

func WithAddSource

func WithAddSource(addSource bool) Option

WithAddSource sets whether to add source information to the log.

func WithCallerSkip

func WithCallerSkip(skip int) Option

WithCallerSkip sets the number of stack frames to skip.

func WithCompress

func WithCompress(compress bool) Option

WithCompress enables or disables log compression.

func WithFilename

func WithFilename(filename string) Option

WithFilename sets the log filename.

func WithFormat

func WithFormat(format string) Option

WithFormat sets the log output format.

func WithLevel

func WithLevel(level slog.Level) Option

WithLevel sets the logging level.

func WithLevelStr

func WithLevelStr(level string) Option

func WithMaxAge

func WithMaxAge(maxAge int) Option

WithMaxAge sets the maximum number of days to retain old log files.

func WithMaxBackups

func WithMaxBackups(maxBackups int) Option

WithMaxBackups sets the maximum number of old log files to retain.

func WithMaxSize

func WithMaxSize(maxSize int) Option

WithMaxSize sets the maximum size of the log file in megabytes.

func WithWriter

func WithWriter(writer io.Writer) Option

WithWriter sets the custom writer for the logger.

Jump to

Keyboard shortcuts

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