From 77a169535877e62778d87315a3be91d262788981 Mon Sep 17 00:00:00 2001 From: i6du <52188840+i6du@users.noreply.github.com> Date: Thu, 4 Jul 2019 14:16:03 +0800 Subject: [PATCH] add send function for convenience (#164) --- README.md | 7 ++++++- event.go | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e5008b9..f7ff10f 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,14 @@ func main() { Str("Scale", "833 cents"). Float64("Interval", 833.09). Msg("Fibonacci is everywhere") + + log.Debug(). + Str("Name", "Tom"). + Send() } -// Output: {"time":1524104936,"level":"debug","Scale":"833 cents","Interval":833.09,"message":"Fibonacci is everywhere"} +// Output: {"level":"debug","Scale":"833 cents","Interval":833.09,"time":1562212768,"message":"Fibonacci is everywhere"} +// Output: {"level":"debug","Name":"Tom","time":1562212768} ``` > You'll note in the above example that when adding contextual fields, the fields are strongly typed. You can find the full list of supported fields [here](#standard-types) diff --git a/event.go b/event.go index 2707bd5..04c3d5b 100644 --- a/event.go +++ b/event.go @@ -105,6 +105,16 @@ func (e *Event) Msg(msg string) { e.msg(msg) } +// Send just like call Msg("") +// +// NOTICE: once this method is called, the *Event should be disposed. +func (e *Event) Send() { + if e == nil { + return + } + e.msg("") +} + // Msgf sends the event with formated msg added as the message field if not empty. // // NOTICE: once this methid is called, the *Event should be disposed.