Skip to content

Commit

Permalink
MsgLazy function added to Event
Browse files Browse the repository at this point in the history
Allows lazy evaluation of msg, only if log level is appropriate.
  • Loading branch information
RobRimmer committed Feb 3, 2022
1 parent 3efdd82 commit f760503
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions event.go
Expand Up @@ -129,6 +129,13 @@ func (e *Event) Msgf(format string, v ...interface{}) {
e.msg(fmt.Sprintf(format, v...))
}

func (e *Event) MsgLazy(createMsg func() string) {
if e == nil {
return
}
e.msg(createMsg())
}

func (e *Event) msg(msg string) {
for _, hook := range e.ch {
hook.Run(e, e.level, msg)
Expand Down

0 comments on commit f760503

Please sign in to comment.