logger

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 6 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = &DBSQLLogger{
	zerolog.New(os.Stderr).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.

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)

Jump to

Keyboard shortcuts

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