Documentation ¶
Overview ¶
Package logzruz provides a logrus hook for sending log messages to logz.io servers for further processing.
The library buffers messages until a user-defined threshold has been reached or a ticker triggers a regular buffer flush. By employing two methods of buffer flushing as well as providing a manual way to send messages, applications can utilise faster logging while making sure messages get sent within a reasonable time frame.
As of now, logzruz will send all message levels to logz.io
Index ¶
Constants ¶
const ( // Version of the logzruz library Version = "1.0.0" // DefaultBufferCount defines the default number of messages to buffer before flushing logs DefaultBufferCount = 10 // DefaultBufferInterval defines the default interval to check for messages to flush if not explicitly specified DefaultBufferInterval = time.Second * 10 // DefaultForceFlushField to use for triggering a buffer flush forcefully if not explicitly specified DefaultForceFlushField = "logzruzForceFlush" // DefaultUserAgent to use for HTTP requests if not explicitly specified DefaultUserAgent = "logzruz v" + Version + " - github.com/MorpheusXAUT/logzruz" // LogzioDefaultURL specifies the default URL of the logz.io service to use LogzioDefaultURL = "https://listener.logz.io:8071/" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook represents a logrus hook for shipping logs to logz.io services. Messages are buffered until a user-defined limit has been reached or sent on a regular interval.
func NewHook ¶
func NewHook(options HookOptions) (*Hook, error)
NewHook creates a new logzruz hook using the provided options
func (*Hook) Fire ¶
Fire is triggered by logrus on every message passed to the hook. The log entry is processed, additional context and data added as required and the JSON encoded payload is added to the message buffer. If the buffer count is reached or a flush is force via log-field or level, the bulk posting is initiated.
func (*Hook) Flush ¶
Flush allows applications to force a buffer flash, sending all stored messages to logz.io
type HookOptions ¶
type HookOptions struct { // App "name" to specify as a type for logz.io requests App string // BufferCount specifies the number of messages to buffer before flushing it (if not triggered by timed triggers before). Setting this value to -1 will disable buffering and instantly send messages (default 10) BufferCount int // BufferInterval specifies the duration to wait between each check for new buffered messages to send (default 10s) BufferInterval time.Duration // Client specifies the HTTP client to use for sending logs to the HTTPS log servers Client *http.Client // Context will be added to every log message Context logrus.Fields // ForceFlushField specifies the name of the log field triggering a force flush if present (default "logzruzForceFlush") ForceFlushField string // ForceFlushLevel allows for log messages higher than the level specified to be flushed instantly (default "fatal") ForceFlushLevel logrus.Level // Token stores the API token to authenticate to logz.io with Token string // URL allows users to overwrite the logz.io URL to send logs to. Should include protocol and port (default "https://listener.logz.io:8071/") URL string // UserAgent allows users to overwrite the default HTTP user-agent set for every request (default "logzruz vX.Y.Z - github.com/MorpheusXAUT/logzruz") UserAgent string }
HookOptions contains all options and settings required to configure the hook. Applications only need to provide a Token, although the other options can be used to further modify the library's behaviour. If not provided, some options will be configured using defaults.