Documentation
¶
Index ¶
- func DBRelativePathLabel(value string) (string, bool)
- func FromContext(ctx context.Context, fallback api.Logger) api.Logger
- func LogPath(dbPath string) (string, error)
- func ResolveEffectiveLevel(configured string, runOverride string, debug bool) string
- func SanitizeMessage(message string) string
- func SetDefaultConsoleOutput(stdout io.Writer, stderr io.Writer) func()
- func WithOperationLogger(ctx context.Context, logger api.Logger) context.Context
- type Entry
- type Level
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) ConsoleEnabled(level Level) bool
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Recent(limit int) []Entry
- func (l *Logger) SetConsoleOutput(stdout io.Writer, stderr io.Writer)
- func (l *Logger) Subscribe(buffer int) (int, <-chan Entry)
- func (l *Logger) Tracef(format string, args ...any)
- func (l *Logger) Unsubscribe(id int)
- func (l *Logger) Warnf(format string, args ...any)
- type OperationLogger
- func (l *OperationLogger) Debugf(format string, args ...any)
- func (l *OperationLogger) Errorf(format string, args ...any)
- func (l *OperationLogger) Infof(format string, args ...any)
- func (l *OperationLogger) Tracef(format string, args ...any)
- func (l *OperationLogger) Warnf(format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DBRelativePathLabel ¶ added in v0.2.3
DBRelativePathLabel returns a slash-normalized .upbrr tmp/cache/log suffix when value is inside a known app DB subdirectory. The boolean is false for paths outside those subdirectories.
func FromContext ¶ added in v0.3.0
FromContext returns the operation logger attached to ctx or fallback. A nil fallback becomes an api.NopLogger.
func LogPath ¶
LogPath returns the app log path, creating the database's logs subdirectory when necessary.
func ResolveEffectiveLevel ¶
ResolveEffectiveLevel applies runOverride first, then the debug fallback, then the configured level.
func SanitizeMessage ¶ added in v0.2.3
SanitizeMessage redacts secrets while preserving ordinary filesystem paths for diagnostics. Callers must sanitize private client endpoints separately.
func SetDefaultConsoleOutput ¶ added in v0.2.1
SetDefaultConsoleOutput replaces the console writers used by new loggers and returns a restore function. Nil writers leave the corresponding output unchanged. A writer implementing WriteConsoleLog(string, string) receives the uppercase level label and sanitized message without console formatting; its implementation must support concurrent calls from logging goroutines.
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.
func ParseLevel ¶
ParseLevel normalizes a configured level. Invalid input returns LevelInfo together with an error.
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
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 ¶
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 ¶
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
ConsoleEnabled reports whether console output admits entries at level.
func (*Logger) Recent ¶
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
SetConsoleOutput replaces the console writers used for stdout and stderr logging. Nil writers leave the corresponding output unchanged.
func (*Logger) Subscribe ¶
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) Unsubscribe ¶
Unsubscribe removes a subscription and closes its channel. Unknown IDs and a nil logger are ignored.
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.