Documentation
¶
Index ¶
- Variables
- func Debug() *zerolog.Event
- func Duration(msg string, start time.Time)
- func Err(err error) *zerolog.Event
- func Error() *zerolog.Event
- func Fatal() *zerolog.Event
- func Info() *zerolog.Event
- func Panic() *zerolog.Event
- func SetLogLevel(l string) error
- func SetLogOutput(w io.Writer)
- func Trace() *zerolog.Event
- func Track(msg string) (string, time.Time)
- func Warn() *zerolog.Event
- type DBSQLLogger
- type ForwardingSink
Constants ¶
This section is empty.
Variables ¶
var Logger = &DBSQLLogger{zerolog.New(output).With().Timestamp().Logger()}
Functions ¶
func Debug ¶
Sets log to debug. 0 You must call Msg on the returned event in order to send the event.
func Err ¶
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 ¶
Sets log to error. 3 You must call Msg on the returned event in order to send the event.
func Fatal ¶
Sets log to fatal. 4 You must call Msg on the returned event in order to send the event.
func Panic ¶
Sets log to panic. 5 You must call Msg on the returned event in order to send the event.
func SetLogLevel ¶
Sets log level. Default is "warn" Available levels are: "trace" "debug" "info" "warn" "error" "fatal" "panic" or "disabled"
func SetLogOutput ¶
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 ¶
Sets log to trace. -1 You must call Msg on the returned event in order to send the event.
Types ¶
type DBSQLLogger ¶
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.