Remove error returned by Msg and Msgf
When error happen, there is nothing the caller can really do and it is not practicle to handle logging errors. Print an error on the standard error instead.
This commit is contained in:
parent
95ecd5ad27
commit
46cd35d1f2
17
event.go
17
event.go
|
@ -3,6 +3,7 @@ package zerolog
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -58,9 +59,9 @@ func (e *Event) Enabled() bool {
|
||||||
//
|
//
|
||||||
// NOTICE: once this method is called, the *Event should be disposed.
|
// NOTICE: once this method is called, the *Event should be disposed.
|
||||||
// Calling Msg twice can have unexpected result.
|
// Calling Msg twice can have unexpected result.
|
||||||
func (e *Event) Msg(msg string) error {
|
func (e *Event) Msg(msg string) {
|
||||||
if !e.enabled {
|
if !e.enabled {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
e.buf = appendString(e.buf, MessageFieldName, msg)
|
e.buf = appendString(e.buf, MessageFieldName, msg)
|
||||||
|
@ -68,16 +69,18 @@ func (e *Event) Msg(msg string) error {
|
||||||
if e.done != nil {
|
if e.done != nil {
|
||||||
defer e.done(msg)
|
defer e.done(msg)
|
||||||
}
|
}
|
||||||
return e.write()
|
if err := e.write(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "zerolog: could not write event: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Msgf sends the event with formated msg added as the message field if not empty.
|
// 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.
|
// NOTICE: once this methid is called, the *Event should be disposed.
|
||||||
// Calling Msg twice can have unexpected result.
|
// Calling Msg twice can have unexpected result.
|
||||||
func (e *Event) Msgf(format string, v ...interface{}) error {
|
func (e *Event) Msgf(format string, v ...interface{}) {
|
||||||
if !e.enabled {
|
if !e.enabled {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf(format, v...)
|
msg := fmt.Sprintf(format, v...)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
|
@ -86,7 +89,9 @@ func (e *Event) Msgf(format string, v ...interface{}) error {
|
||||||
if e.done != nil {
|
if e.done != nil {
|
||||||
defer e.done(msg)
|
defer e.done(msg)
|
||||||
}
|
}
|
||||||
return e.write()
|
if err := e.write(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "zerolog: could not write event: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dict adds the field key with a dict to the event context.
|
// Dict adds the field key with a dict to the event context.
|
||||||
|
|
Loading…
Reference in New Issue