logging

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package logging provides structured file logging with a bash-compatible format.

BracketHandler implements slog.Handler and produces output in the format:

[2024-01-15 10:30:00] [INFO] message

This matches the log format from the original bash SSU script.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(logDir string, verbose bool, maxSizeMB, maxBackups int) (*slog.Logger, error)

InitLogger creates a slog.Logger that writes to a rotating log file.

The log file is created at logDir/submodule-update.log and rotated by lumberjack when it exceeds maxSizeMB megabytes, keeping up to maxBackups old files.

When verbose is true, a second handler writes DEBUG+ output to stderr. When verbose is false, only INFO+ goes to the file and nothing to stderr.

func LogDir

func LogDir(projectName string) string

LogDir returns the standard log directory path for a project: ~/.ssu/<projectName>/logs

Types

type BracketHandler

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

BracketHandler is a slog.Handler that writes log records in bracket format. It is safe for concurrent use.

func NewBracketHandler

func NewBracketHandler(w io.Writer, level slog.Level) *BracketHandler

NewBracketHandler creates a BracketHandler that writes to w at the given level.

func (*BracketHandler) Enabled

func (h *BracketHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*BracketHandler) Handle

func (h *BracketHandler) Handle(_ context.Context, r slog.Record) error

Handle formats and writes a log record in bracket format.

func (*BracketHandler) WithAttrs

func (h *BracketHandler) WithAttrs(_ []slog.Attr) slog.Handler

WithAttrs returns the handler unchanged. SSU uses simple messages without structured attributes in file logs.

func (*BracketHandler) WithGroup

func (h *BracketHandler) WithGroup(_ string) slog.Handler

WithGroup returns the handler unchanged.

type MultiHandler

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

MultiHandler fans out log records to multiple slog.Handler implementations.

func (*MultiHandler) Enabled

func (m *MultiHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether any of the underlying handlers is enabled for the level.

func (*MultiHandler) Handle

func (m *MultiHandler) Handle(ctx context.Context, r slog.Record) error

Handle writes the record to every enabled handler.

func (*MultiHandler) WithAttrs

func (m *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new MultiHandler where each underlying handler has the attrs.

func (*MultiHandler) WithGroup

func (m *MultiHandler) WithGroup(name string) slog.Handler

WithGroup returns a new MultiHandler where each underlying handler has the group.

Jump to

Keyboard shortcuts

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