Skip to content

Commit

Permalink
MsgFunc function added to Event
Browse files Browse the repository at this point in the history
Allows lazy evaluation of msg text, only if log level is appropriate.
  • Loading branch information
RobRimmer committed Feb 3, 2022
1 parent 3efdd82 commit 402ec20
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) MsgFunc(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 402ec20

Please sign in to comment.