rs / zerolog

Zero Allocation JSON Logger
MIT License
10.61k stars 572 forks source link

ErrorHandler #569

Open GanBob opened 1 year ago

GanBob commented 1 year ago

please,I want a private ErrorHandler,not global

func (e *Event) msg(msg string) {
    for _, hook := range e.ch {
        hook.Run(e, e.level, msg)
    }
    if msg != "" {
        e.buf = enc.AppendString(enc.AppendKey(e.buf, MessageFieldName), msg)
    }
    if e.done != nil {
        defer e.done(msg)
    }
    if err := e.write(); err != nil {
        if ErrorHandler != nil {   //why here is a global ErrorHandler?
            ErrorHandler(err)
        } else {
            fmt.Fprintf(os.Stderr, "zerolog: could not write event: %v\n", err)
        }
    }
}
mitar commented 1 year ago

Maybe explain a bit your use case? Why you do not want global error handler? Logging is generally done for the whole program globally?

GanBob commented 1 year ago

Thank you for your reply.In my usage scenario, I will connect to multiple different syslog servers at the same time. If one of the services is abnormal, I cannot handle it specifically.