sirupsen / logrus

Structured, pluggable logging for Go.
MIT License
24.3k stars 2.26k forks source link

Unclear on documentation regarding Hook interface #1421

Closed ronaldpetty closed 2 months ago

ronaldpetty commented 4 months ago

I think I am misreading the following. It sounds to me that the Fire() method would not be called if in a goroutine. From my testing it seems that they are called. Or is this saying that Levels() is not checked and Fire simply happens and we should run Levels to see if want to log and in turn Fire in a goroutine? Sorry for my confusion.

$ go doc github.com/sirupsen/logrus.Hook
package logrus // import "github.com/sirupsen/logrus"

type Hook interface {
    Levels() []Level
    Fire(*Entry) error
}
    A hook to be fired when logging on the logging levels returned from
    `Levels()` on your implementation of the interface. Note that this is not
    fired in a goroutine or a channel with workers, you should handle such
    functionality yourself if your call is non-blocking and you don't wish for
    the logging calls for levels returned from `Levels()` to block.
ronaldpetty commented 4 months ago

The part I am hung up on (I think) is "this is not fired in a goroutine ..". I think it implies "Note that Levels() is not fired during calls to log (e.g. logger.info), you should handle such ...". I was confused because "main" is a goroutine and Levels is called when adding hooks. But later, when calling logger.info for example, Levels is not called (in a goroutine or non-goroutine).

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.