log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureStderr

func CaptureStderr() error

CaptureStderr redirects file descriptor 2 (stderr) through a pipe so that output from C libraries (e.g. libdqlite/libraft) is captured and routed through the structured logger instead of appearing as raw, colorized text.

The original stderr fd is preserved via dup so that fatal/crash output from the Go runtime still reaches the terminal.

func Clean

func Clean(msg string) string

Clean sanitizes a log message to be lower case and removes newline characters.

func Debug

func Debug(msg string, kv ...any)

Debug logs a debug message. Refer to: https://godoc.org/go.uber.org/zap for more details.

func Error

func Error(msg string, kv ...any)

Error logs an error message. Refer to: https://godoc.org/go.uber.org/zap for more details.

func Fatal

func Fatal(msg string, kv ...any)

Fatal logs a fatal message. Refer to: https://godoc.org/go.uber.org/zap for more details.

func GetLevel

func GetLevel() zapcore.Level

GetLevel returns the current log level.

func Info

func Info(msg string, kv ...any)

Info logs an info message. Refer to: https://godoc.org/go.uber.org/zap for more details.

func Panic

func Panic(msg string, kv ...any)

Panic logs a panic message. Refer to: https://godoc.org/go.uber.org/zap for more details.

func SetLevel

func SetLevel(level string) error

SetLevel sets the log level by specifying a string which can be any of: ["DEBUG", "INFO", "WARNING", "ERROR", "PANIC", "FATAL"], case-insensitive.

func ToStderr

func ToStderr()

ToStderr routes structured logs to stderr. CLI commands call this so that stdout carries only the command's machine-readable output (e.g. a `caesium receipt get` JSON receipt that gets piped into `caesium verify`). The server does NOT use this — it logs to stdout and captures C-library stderr separately (see CaptureStderr), where routing logs to stderr would feed the capture pipe back into the logger.

func ToStdout

func ToStdout()

ToStdout routes structured logs to stdout (the server default). Used to restore stdout logging before the server installs its stderr capture.

func Warn

func Warn(msg string, kv ...any)

Warn logs a warning message. Refer to: https://godoc.org/go.uber.org/zap for more details.

Types

type LogEntry

type LogEntry struct {
	Sequence  uint64          `json:"sequence"`
	Timestamp time.Time       `json:"ts"`
	Level     string          `json:"level"`
	Message   string          `json:"msg"`
	Caller    string          `json:"caller,omitempty"`
	Fields    json.RawMessage `json:"fields,omitempty"`
}

LogEntry is a single structured log record stored in the ring buffer.

type RingBuffer

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

RingBuffer is a bounded, thread-safe circular buffer of log entries that also implements zapcore.Core so it can be tee'd alongside the primary stdout core.

func Buffer

func Buffer() *RingBuffer

Buffer returns the global ring buffer for log streaming.

func NewRingBuffer

func NewRingBuffer(size int, level zapcore.Level) *RingBuffer

NewRingBuffer creates a ring buffer that stores up to size entries.

func (*RingBuffer) Check

func (*RingBuffer) Enabled

func (rb *RingBuffer) Enabled(lvl zapcore.Level) bool

func (*RingBuffer) Snapshot

func (rb *RingBuffer) Snapshot() []LogEntry

Snapshot returns a copy of all buffered entries in chronological order.

func (*RingBuffer) Subscribe

func (rb *RingBuffer) Subscribe(ctx context.Context) <-chan LogEntry

Subscribe returns a channel that receives live log entries. The channel is closed when ctx is cancelled. Sends are non-blocking; entries are dropped if the subscriber cannot keep up.

func (*RingBuffer) Sync

func (rb *RingBuffer) Sync() error

func (*RingBuffer) With

func (rb *RingBuffer) With(fields []zapcore.Field) zapcore.Core

func (*RingBuffer) Write

func (rb *RingBuffer) Write(entry zapcore.Entry, fields []zapcore.Field) error

Jump to

Keyboard shortcuts

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