MsgFunc function added to Event (#406)

Allows lazy evaluation of msg text, only if log level is appropriate.
This commit is contained in:
RobRimmer 2022-02-03 14:03:11 +00:00 committed by GitHub
parent 025f9f1819
commit fc26014bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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)