add send function for convenience (#164)

This commit is contained in:
i6du 2019-07-04 14:16:03 +08:00 committed by Olivier Poitrey
parent 60d4b07b61
commit 77a1695358
2 changed files with 16 additions and 1 deletions

View File

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

View File

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