logger

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logger provides structured logging with levels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedConfig

type BufferedConfig struct {
	FlushInterval time.Duration // default 500ms
	BufferSize    int           // default 50 entries
	MaxFileSize   int64         // default 50 MB; 0 = no rotation
	MaxBackups    int           // default 2
	FilePath      string        // if empty, uses direct writer
}

BufferedConfig configures the buffered writer.

type Level

type Level int

Level represents a log level.

const (
	Debug Level = iota
	Info
	Warn
	Error
	Fatal
)

func (Level) String

func (l Level) String() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a structured logger.

func Default

func Default() *Logger

Default returns a default logger writing to stderr at Info level.

func New

func New(output io.Writer, level Level) *Logger

New creates a new logger.

func NewWithDeps

func NewWithDeps(deps LoggerDeps) *Logger

NewWithDeps creates a new logger from a deps struct. Zero-value fields are replaced with production defaults. Note: Level zero-value is Debug (iota=0), so use Default() for Info-level logger.

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...map[string]interface{})

Debug logs a debug message.

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...map[string]interface{})

Error logs an error message.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...map[string]interface{})

Fatal logs a fatal message and exits.

func (*Logger) FlushForTesting

func (l *Logger) FlushForTesting()

FlushForTesting synchronously flushes any buffered output. Test-only; not for production use.

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...map[string]interface{})

Info logs an info message.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel sets the minimum log level.

func (*Logger) SetOutputForTesting

func (l *Logger) SetOutputForTesting(w io.Writer)

SetOutputForTesting replaces the logger's output writer. Test-only; not for production use.

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...map[string]interface{})

Warn logs a warning message.

func (*Logger) WithPrefix

func (l *Logger) WithPrefix(prefix string) *Logger

WithPrefix returns a new logger with the given prefix.

type LoggerDeps

type LoggerDeps struct {
	Output io.Writer // default: os.Stderr
	Level  Level     // default: Info
}

LoggerDeps holds configurable dependencies for Logger. Zero values are filled with production defaults by NewWithDeps.

Jump to

Keyboard shortcuts

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