Documentation
¶
Overview ¶
The flogger package provides a simple function call logging by wrapping github.com/rs/zerolog package.
Index ¶
- Variables
- type FuncCall
- func (fc *FuncCall) Debug() *zerolog.Event
- func (fc *FuncCall) Error() *zerolog.Event
- func (fc *FuncCall) Exit(params ...interface{})
- func (fc *FuncCall) Info() *zerolog.Event
- func (fc *FuncCall) OnExit(params ...interface{}) *FuncCall
- func (fc *FuncCall) Trace() *zerolog.Event
- func (fc *FuncCall) Warn() *zerolog.Event
- type FuncLogger
Constants ¶
This section is empty.
Variables ¶
var ExitHandler = func(fc *FuncCall) { if fc.IsSilentEnter && len(fc.Params) == 0 { return } e := fc.log.Debug().Str("func", fc.Name). Int64("dur", int64(time.Since(fc.EnteredAt))) if len(fc.Params) > 0 { e = e.Str("params", fmt.Sprintf("%+v", fc.Params)) } if fc.IsSilentEnter { e.Msg("enter/exit") } else { e.Msg("exit") } return }
ExitHandler implements default behavior on exit.
If the function started with EnterSilent(), Exit() will be silent as well. If was called OnExit() between, then Exit() lost silence.
var G = FuncLogger{/* contains filtered or unexported fields */}
G holds global default logger. Use flooger.G to use features without custom FuncLogger.
Functions ¶
This section is empty.
Types ¶
type FuncCall ¶ added in v0.0.2
type FuncCall struct {
*FuncLogger
// Name holds function name.
Name string
// EnteredAt time captured by Enter or EnterSilent.
EnteredAt time.Time
// IsSilentEnter holds true if the FunCall build by EnterSilent method.
IsSilentEnter bool
// Params hold values to be printed in Exit().
Params []interface{}
// Ignore holds true if zerolog.Level not DebugLevel or TraceLevel.
Ignore bool
}
FuncCall holds data needed for a sigle function call tracking and logging.
func (*FuncCall) Debug ¶ added in v0.0.2
Debug return zerolog.Event for writing intermetiate log items between Enter() and Exit().
func (*FuncCall) Error ¶ added in v0.0.2
Error return zerolog.Event for writing intermediate log items between Enter() and Exit().
func (*FuncCall) Exit ¶ added in v0.0.2
func (fc *FuncCall) Exit(params ...interface{})
Exit writes to the log function execution duration. If you dont want have 2 log lines in the log (for enter and exit) you can have 1 log line by calling defer flog.EnterSilent().Exit(id, name, age).
func (*FuncCall) Info ¶ added in v0.0.2
Info return zerolog.Event for writing intermetiate log items between Enter() and Exit().
func (*FuncCall) OnExit ¶ added in v0.0.3
OnExit informs silent function call, that parameters should be written to the log in the Exit() call.
type FuncLogger ¶ added in v0.0.2
type FuncLogger struct {
// contains filtered or unexported fields
}
FuncLogger wraps zerolog logger with type/name pair.
func New ¶
func New(l *zerolog.Logger, typ, name string) FuncLogger
New builds new FuncLogger object. Parameters typ and name will be placed to the log item.
func (*FuncLogger) Enter ¶ added in v0.0.2
func (fl *FuncLogger) Enter(params ...interface{}) *FuncCall
Enter builds FuncCall object and writes message "enter" to the log. Log item gets func name and all input parameters.
func (*FuncLogger) EnterSilent ¶ added in v0.0.2
func (fl *FuncLogger) EnterSilent() *FuncCall
EnterSilent builds FuncCall object but does not write enter message to the log.
func (*FuncLogger) Logger ¶ added in v0.0.2
func (fl *FuncLogger) Logger() zerolog.Logger
Logger returns logger instance.
func (*FuncLogger) SetSecondExitHandler ¶ added in v0.0.3
func (fl *FuncLogger) SetSecondExitHandler(f func(*FuncCall)) *FuncLogger
SetSecondExitHandler assigns secondary handler to be called in Exit().