MsgFunc function added to Event (#406)
Allows lazy evaluation of msg text, only if log level is appropriate.
This commit is contained in:
parent
025f9f1819
commit
fc26014bd4
7
event.go
7
event.go
|
@ -129,6 +129,13 @@ func (e *Event) Msgf(format string, v ...interface{}) {
|
||||||
e.msg(fmt.Sprintf(format, v...))
|
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) {
|
func (e *Event) msg(msg string) {
|
||||||
for _, hook := range e.ch {
|
for _, hook := range e.ch {
|
||||||
hook.Run(e, e.level, msg)
|
hook.Run(e, e.level, msg)
|
||||||
|
|
Loading…
Reference in New Issue