logger

package
v1.15.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = &DBSQLLogger{zerolog.New(output).With().Timestamp().Logger()}

Functions

func Debug

func Debug() *zerolog.Event

Sets log to debug. 0 You must call Msg on the returned event in order to send the event.

func Duration

func Duration(msg string, start time.Time)

Duration is a convenience function to log elapsed time. Often used with Track

func Err

func Err(err error) *zerolog.Event

Err starts a new message with error level with err as a field if not nil or with info level if err is nil. You must call Msg on the returned event in order to send the event.

func Error

func Error() *zerolog.Event

Sets log to error. 3 You must call Msg on the returned event in order to send the event.

func Fatal

func Fatal() *zerolog.Event

Sets log to fatal. 4 You must call Msg on the returned event in order to send the event.

func Info

func Info() *zerolog.Event

Sets log to info. 1 You must call Msg on the returned event in order to send the event.

func Panic

func Panic() *zerolog.Event

Sets log to panic. 5 You must call Msg on the returned event in order to send the event.

func SetLogLevel

func SetLogLevel(l string) error

Sets log level. Default is "warn" Available levels are: "trace" "debug" "info" "warn" "error" "fatal" "panic" or "disabled"

func SetLogOutput

func SetLogOutput(w io.Writer)

Sets logging output. Default is os.Stderr. If in terminal, pretty logs are enabled. A nil writer is treated as io.Discard. Existing logger values (and the kernel log bridge) follow later calls to this function.

Writes are serialized per destination. If you hot-swap the output under concurrent logging while reusing the same underlying writer across swaps, pass a writer that is safe for concurrent use (os.File is; a bare bytes.Buffer is not): records in flight across a swap are serialized by that writer, not by the driver.

The writer must not log through this driver from within its own Write/WriteLevel, directly or indirectly: per-destination serialization holds a non-reentrant lock across the write, so a re-entrant writer deadlocks (and a truly self-referential one would recurse without bound regardless). As with any logging library, do not log from your log destination.

func Trace

func Trace() *zerolog.Event

Sets log to trace. -1 You must call Msg on the returned event in order to send the event.

func Track

func Track(msg string) (string, time.Time)

Track is a convenience function to track time spent

func Warn

func Warn() *zerolog.Event

Sets log to warn. 2 You must call Msg on the returned event in order to send the event.

Types

type DBSQLLogger

type DBSQLLogger struct {
	zerolog.Logger
}

func WithContext

func WithContext(connectionId string, correlationId string, queryId string) *DBSQLLogger

WithContext sets connectionId, correlationId, and queryId to be used as fields.

func (*DBSQLLogger) Duration

func (l *DBSQLLogger) Duration(msg string, start time.Time)

Duration logs a debug message with the time elapsed between the provided start and the current time. Use in conjunction with Track.

For example:

msg, start := log.Track("Run operation")
defer log.Duration(msg, start)

func (*DBSQLLogger) Track

func (l *DBSQLLogger) Track(msg string) (string, time.Time)

Track is a simple utility function to use with logger to log a message with a timestamp. Recommended to use in conjunction with Duration.

For example:

msg, start := log.Track("Run operation")
defer log.Duration(msg, start)

type ForwardingSink added in v1.15.0

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

ForwardingSink emits already-rendered log records from an external source (such as the Rust kernel) to the driver's shared destination. It follows SetLogOutput and bypasses Logger's level gate and timestamp hook, so the source can supply its own level and its own (emission-time) timestamp.

It is deliberately NOT an io.Writer — and neither is the *zerolog.Event it hands out. A forwarding sink that is an io.Writer can be passed to SetLogOutput, which wraps it in a SyncWriter and stores it as the destination; the sink's own writes then route back through that same SyncWriter (output → SyncWriter → sink → output), and because SyncWriter holds its mutex across the write, the next record deadlocks. Handing out a Logger fails the same way (zerolog.Logger implements io.Writer). A method-only sink cannot form that cycle.

func NewForwardingSink added in v1.15.0

func NewForwardingSink() *ForwardingSink

NewForwardingSink returns a sink over the shared output, ungated at TraceLevel because the external source has already applied its own level filter.

func (*ForwardingSink) Event added in v1.15.0

func (s *ForwardingSink) Event(level zerolog.Level) *zerolog.Event

Event begins a record at level on the shared destination; the caller adds fields and terminates with Msg. Like Logger, it follows SetLogOutput.

Jump to

Keyboard shortcuts

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