Skip to content

Commit

Permalink
MsgFunc function added to Event (rs#406)
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 authored and pablitoc committed Apr 7, 2023
1 parent 6cda783 commit 8977f7c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions event.go
Expand Up @@ -140,6 +140,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.ctx, e, e.level, msg)
Expand Down

0 comments on commit 8977f7c

Please sign in to comment.