Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAsyncQueueFull = errors.New("async hook queue is full")
ErrAsyncQueueFull is the error returned when the async queue is full.
Functions ¶
func AddAlertHook ¶
AddAlertHook attaches a custom logrus Hook for generating alert notifications based on configured levels and channels. It supports both synchronous and asynchronous operation modes, with optional graceful shutdown integration.
Types ¶
type AlertHook ¶
type AlertHook struct {
// contains filtered or unexported fields
}
AlertHook logrus hooks to send specified level logs as text message for alerting.
func NewAlertHook ¶
NewAlertHook constructor to new AlertHook instance.
type AsyncHook ¶
type AsyncHook struct {
logrus.Hook // Embedded logrus hook.
AsyncOption // Embedded options.
// contains filtered or unexported fields
}
AsyncHook is a logrus hook that processes log entries asynchronously.
func NewAsyncHook ¶
func NewAsyncHook(hook logrus.Hook, opts AsyncOption) *AsyncHook
NewAsyncHook initializes and starts a standard AsyncHook without graceful shutdown handling. Use this when you don't require integration with a graceful shutdown mechanism.
func NewAsyncHookWithCtx ¶
func NewAsyncHookWithCtx( ctx context.Context, wg *sync.WaitGroup, hook logrus.Hook, opts AsyncOption) *AsyncHook
NewAsyncHookWithCtx initializes and starts a new AsyncHook instance that integrates with graceful shutdown handling. It's designed to work harmoniously with the application's shutdown process to ensure no logs are lost during shutdown.
type AsyncOption ¶
type AsyncOption struct {
NumWorkers int // Number of worker goroutines. If set to 0 (default), async mode is disabled.
QueueSize int `default:"60"` // Maximum number of queued jobs.
StopTimeout time.Duration `default:"5s"` // Timeout duration before forced exit of async processing.
}
AsyncOption defines configuration options for the AsyncHook.
type Config ¶
type Config struct {
// Level is the minimum logrus level at which alerts will be triggered.
Level string `default:"warn"`
// Channels lists the default alert notification channels to use.
Channels []string
// Maximum request timeout allowed to send alert.
SendTimeout time.Duration `default:"3s"`
// Async configures the behavior of the asynchronous worker for handling log alerts.
Async AsyncOption
}