From 484fd91452ed6f02630e6797e91dee3dbbd410e2 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Fri, 17 Feb 2023 21:00:43 -0500 Subject: [PATCH] Add comment --- log/event.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/log/event.go b/log/event.go index 4ab04399..55c43091 100644 --- a/log/event.go +++ b/log/event.go @@ -129,20 +129,13 @@ func (e *Event) With(contexts ...Contexter) *Event { return e } -// maybeLog logs the event to the defined output. The event is only logged, if -// either the global log level is >= l, or if the log level in one of the overrides matches +// Render returns the rendered log event as a string, or an empty string. The event is only rendered, +// if either the global log level is >= l, or if the log level in one of the overrides matches // the level. // // If no overrides are defined (default), the Contexter array is not applied unless the event // is actually logged. If overrides are defined, then Contexters have to be applied in any case // to determine if they match. This is super complicated, but required for efficiency. -func (e *Event) maybeLog(l Level, message string, v ...any) { - m := e.Render(l, message, v...) - if m != "" { - log.Println(m) - } -} - func (e *Event) Render(l Level, message string, v ...any) string { appliedContexters := e.maybeApplyContexters() if !e.shouldLog(l) { @@ -160,6 +153,13 @@ func (e *Event) Render(l Level, message string, v ...any) string { return e.String() } +// maybeLog logs the event to the defined output, or does nothing if Render returns an empty string +func (e *Event) maybeLog(l Level, message string, v ...any) { + if m := e.Render(l, message, v...); m != "" { + log.Println(m) + } +} + // Loggable returns true if the given log level is lower or equal to the current log level func (e *Event) Loggable(l Level) bool { return e.globalLevelWithOverride() <= l