Documentation
¶
Overview ¶
Package logger provides structured logging utilities wrapping log/slog.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a new structured logger with sensible defaults.
Default configuration:
- Level: info
- Format: json
- Output: os.Stderr
Example:
log := logger.New(logger.Config{
Level: "debug",
Format: "text",
})
log.Info("server started", "port", 8080)
func NewDefault ¶
NewDefault creates a logger with default settings (info level, JSON format, stderr).
func NewFile ¶
NewFile creates a logger that writes to a temp file.
This is useful for TUI applications where stdout must remain clean. The logger writes JSON-formatted structured logs.
Returns the logger, a cleanup function to close the file, and any error. The cleanup function should be deferred immediately after calling this.
Log file location: {os.TempDir()}/{appName}.log
Example:
log, cleanup, err := logger.NewFile("myapp")
if err != nil {
return err
}
defer cleanup()
log.Info("application started")
// Logs written to /tmp/myapp.log (or equivalent)
Types ¶
Click to show internal directories.
Click to hide internal directories.