logging

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBRelativePathLabel added in v0.2.3

func DBRelativePathLabel(value string) (string, bool)

DBRelativePathLabel returns a slash-normalized .upbrr tmp/cache/log suffix when value is inside a known app DB subdirectory. The boolean is false for ordinary local paths that should be replaced with a generic label.

func FromContext added in v0.3.0

func FromContext(ctx context.Context, fallback api.Logger) api.Logger

FromContext returns the operation logger attached to ctx or fallback. A nil fallback becomes an api.NopLogger.

func LogPath

func LogPath(dbPath string) (string, error)

LogPath returns the app log path, creating the database's logs subdirectory when necessary.

func ResolveEffectiveLevel

func ResolveEffectiveLevel(configured string, runOverride string, debug bool) string

ResolveEffectiveLevel applies runOverride first, then the debug fallback, then the configured level.

func SanitizeMessage added in v0.2.3

func SanitizeMessage(message string) string

SanitizeMessage redacts secrets and replaces local filesystem paths in user-shareable log or terminal output with stable labels. Exact save_path field values remain visible for client-path diagnostics. Paths under known app DB tmp/cache/log directories keep only their .upbrr-relative suffix; other local paths become [local path].

func SetDefaultConsoleOutput added in v0.2.1

func SetDefaultConsoleOutput(stdout io.Writer, stderr io.Writer) func()

SetDefaultConsoleOutput replaces the console writers used by new loggers and returns a restore function. Nil writers leave the corresponding output unchanged.

func WithOperationLogger added in v0.3.0

func WithOperationLogger(ctx context.Context, logger api.Logger) context.Context

WithOperationLogger attaches one operation-local logger view to ctx. It returns ctx unchanged when ctx or logger is nil.

Types

type Entry

type Entry struct {
	ID      int64     `json:"id"`
	Time    time.Time `json:"time" ts_type:"string"`
	Level   string    `json:"level"`
	Message string    `json:"message"`
}

Entry is one sanitized retained log entry. IDs increase within a Logger, and Level contains the lowercase level name.

type Level

type Level int

Level is a maximum verbosity threshold: larger values admit progressively more detailed entries, while LevelError admits errors only.

const (
	LevelError Level = iota
	LevelWarn
	LevelInfo
	LevelDebug
	LevelTrace
)

func ParseLevel

func ParseLevel(value string) (Level, error)

ParseLevel normalizes a configured level. Invalid input returns LevelInfo together with an error.

func (Level) String

func (l Level) String() string

type Logger

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

Logger writes sanitized, threshold-filtered entries to console and optional file outputs. An optional console threshold can differ from the application threshold used by file output, snapshots, and subscribers. Close releases the optional file output.

func New

func New(cfg config.LoggingConfig, dbPath string) (*Logger, error)

New constructs a logger using cfg.Level. When file output is enabled, it creates or opens the app log below the database directory; callers must close the returned logger.

func NewWithConsoleLevel added in v0.3.2

func NewWithConsoleLevel(cfg config.LoggingConfig, dbPath string, override string) (*Logger, error)

NewWithConsoleLevel constructs a logger using cfg.Level for application logging and a non-blank override for console output only. Callers must close the returned logger when file output is enabled.

func NewWithLevel

func NewWithLevel(cfg config.LoggingConfig, dbPath string, override string) (*Logger, error)

NewWithLevel constructs a logger after replacing cfg.Level with a non-blank override. It has the same file ownership and side effects as New.

func (*Logger) Close

func (l *Logger) Close() error

Close releases file logging resources. It is safe on a nil logger and is a no-op when file logging is disabled.

func (*Logger) ConsoleEnabled added in v0.3.2

func (l *Logger) ConsoleEnabled(level Level) bool

ConsoleEnabled reports whether console output admits entries at level.

func (*Logger) Debugf

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

func (*Logger) Errorf

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

func (*Logger) Infof

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

func (*Logger) Recent

func (l *Logger) Recent(limit int) []Entry

Recent returns a copied, oldest-to-newest snapshot of the most recent entries. A non-positive or oversized limit returns the complete retained buffer.

func (*Logger) SetConsoleOutput added in v0.2.1

func (l *Logger) SetConsoleOutput(stdout io.Writer, stderr io.Writer)

SetConsoleOutput replaces the console writers used for stdout and stderr logging. Nil writers leave the corresponding output unchanged.

func (*Logger) Subscribe

func (l *Logger) Subscribe(buffer int) (int, <-chan Entry)

Subscribe registers a future-entry stream and returns its unsubscribe ID. A non-positive buffer uses the package default. Delivery is non-blocking, so entries are dropped for a subscriber whose channel is full.

func (*Logger) Tracef

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

func (*Logger) Unsubscribe

func (l *Logger) Unsubscribe(id int)

Unsubscribe removes a subscription and closes its channel. Unknown IDs and a nil logger are ignored.

func (*Logger) Warnf

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

type OperationLogger added in v0.3.0

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

OperationLogger is an immutable non-owning verbosity view over one active logger. Entries use the root logger's sanitized outputs, buffer, and subscribers without changing its configured application or console threshold.

func NewOperationLogger added in v0.3.0

func NewOperationLogger(root *Logger, override string) (*OperationLogger, error)

NewOperationLogger creates a non-owning logger view. An empty override uses the root logger's configured level. A nil root or invalid override returns an error.

func (*OperationLogger) Debugf added in v0.3.0

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

Debugf logs a debug entry when enabled by this operation view.

func (*OperationLogger) Errorf added in v0.3.0

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

Errorf logs an error entry when enabled by this operation view.

func (*OperationLogger) Infof added in v0.3.0

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

Infof logs an info entry when enabled by this operation view.

func (*OperationLogger) Tracef added in v0.3.0

func (l *OperationLogger) Tracef(format string, args ...any)

Tracef logs a trace entry when enabled by this operation view.

func (*OperationLogger) Warnf added in v0.3.0

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

Warnf logs a warning entry when enabled by this operation view.

Jump to

Keyboard shortcuts

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