View Source LoggerHTTP.Handler (logger_http v0.1.0)
A configurable :logger
handler
that sends logged messages through HTTP.
Features
This logger handler provides the features listed here.
Overload protection
This handler has built-in overload protection
via the :sync_threshold
and :drop_threshold
configuration options. Under normal
circumstances, the logs are sent asynchronously to the HTTP endpoint, returning control
to the caller immediately. However, if the number of queued logs exceeds the configured
:sync_threshold
, the handler will switch to synchronous mode, blocking the logging
process until the logs are sent. Moreover, if the number of queued logs exceeds the
:drop_threshold
, the handler will start dropping logs to prevent the system from
becoming unresponsive.
Choosing the right values
Since sending the logs is batched and there is a pool of processes, it is not abnormal to have a few logs queued. With the default configuration,
:batch_size
*:pool_size
means at least a hundred logs can be queued before being sent. Keep this in mind when overriding the defaults, or you might end up in sync or drop mode too early!
Configuration
This handler supports the following configuration options:
:url
(String.t/0
) - Required. The HTTP endpoint to send logs to.:adapter
- Configuration for the adapter module, used both to send logs and handle errors.The value can be one of the following:
- a keyword list to configure the default adapter
LoggerHTTP.Adapter.Req
, - a module implementing the
LoggerHTTP.Adapter
behaviour to use a custom adapter, - a 2-tuple containing a module and a keyword list to use a configured custom adapter.
The configuration is validated by the callback
LoggerHTTP.Adapter.cast_options/1
of the adapter.The default value is
{LoggerHTTP.Adapter.Req, []}
.- a keyword list to configure the default adapter
:batch_size
(integer/0
) - The maximum number of logs to queue before making an HTTP request. If the timeout configured by:batch_timeout
is reached before the queue as reached the configured size, less logs will be sent. Setting this parameter to 1 will effectively disable batching. The default value is10
.:batch_timeout
(integer/0
) - The maximum time to wait before sending a batch of logs, in milliseconds. If the queue reaches the size configured bybatch_size
before this timeout, the logs will be sent. This parameter is only used whenbatch_size
is greater than 1. It can also be disabled by settings the value to0
. The default value is5000
.:pool_size
(integer/0
) - LoggerHTTP uses a pool of GenServers to make HTTP requests. The log are evenly distributed among the processes in the pool. This option allows you to configure the size of the pool.The default is the result of
max(10, System.schedulers_online())
.:sync_threshold
(integer/0
) - The maximum of queued logs before switching to synchronous mode. In synchronous mode, the logger will await for logs to be sent before returning control to the caller. This option, along withdrop_threshold
, effectively implements overload protection. The default value is300
.:drop_threshold
(integer/0
) - The maximum of queued logs before dropping logs. This option, along withsync_threshold
, effectively implements overload protection. The default value is2000
.