Logging
This article describes the Fluentd logging mechanism.
Fluentd has two logging layers: global and per plugin. Different log levels can be set for global logging and plugin level logging.
Log Level
Here is the list of supported levels in increasing order of verbosity:
fatal
error
warn
info
debug
trace
The default log level is info
, and Fluentd outputs info
, warn
, error
and fatal
logs by default.
Global Logs
Global logging is used by Fluentd core and plugins that do not set their own log levels. The global log level can be adjusted up or down.
By Command Line Option
Increase Verbosity Level
The -v
option sets the verbosity to debug
while the -vv
option sets the verbosity to trace
.
These options are useful for debugging purposes.
Decrease Verbosity Level
The -q
option sets the verbosity to warn
while the -qq
option sets the verbosity to error
:
By Config File
You can also configure the logging level in <system>
section:
Per Plugin Log
The @log_level
option sets different levels of logging for each plugin. It can be set in each plugin's configuration file.
For example, in order to debug in_tail
and to suppress all but fatal log messages for in_http
, their respective @log_level
options should be set as follows:
If you do not specify the @log_level
parameter, the plugin will use the global log level.
Log Format
Following format are supported:
text
(default)json
The format can be configured through <log>
directive under <system>
:
With this setting, the following log line:
is changed to:
Suppress log/stacktrace messages
Fluentd provides two parameters to suppress log/stacktrace messages
ignore_repeated_log_interval
(since v1.10.2)ignore_same_log_interval
(since v1.11.3)
ignore_repeated_log_interval
ignore_repeated_log_interval
Under high loaded environment, output destination sometimes becomes unstable and it causes lots of same log message. This parameter mitigates such situation.
ignore_same_log_interval
ignore_same_log_interval
This is similar to ignore_repeated_log_inteval
but covers more usecases. For example, if the plugin generates several log messages in one action, logs are not repeated:
ignore_same_log_interval
resolves these cases.
Output to Log File
By default, Fluentd outputs to the standard output. Use -o
command line option to specify the file instead:
Log Rotation Setting
By default, Fluentd does not rotate log files. You can configure this behavior via system-config after v1.13.0.
It can be configured through <log>
directive under <system>
:
You need to specify rotate_age
or rotate_size
options explicitly to enable log rotation.
NOTE: You can omit one of these 2 options to use the default value, but if you omit both of them, log rotation is disabled. Actually, an external library manages these default values, resulting in this complication.
You can use command-line options too (mainly for before v1.13.0):
--log-rotate-age AGE
--log-rotate-age AGE
AGE
is an integer or a string:
integer: Generations to keep rotated log files.
string: frequency of rotation. (Supported:
daily
,weekly
,monthly
)
NOTE: When --log-rotate-age
is specified on Windows, log files are separated into log-supervisor-0.log
, log-0.log
, ..., log-N.log
where N
is generation - 1
due to the system limitation. Windows does not permit delete and rename files simultaneously owned by another process.
--log-rotate-size BYTES
--log-rotate-size BYTES
The byte size to rotate log files. This is applied when --log-rotate-age
is specified with integer:
Here is an example:
NOTE: When --log-rotate-size
is specified on Windows, log files are separated into log-supervisor-0.log
, log-0.log
, ..., log-N.log
where N
is generation - 1
due to the system limitation. Windows does not permit delete and rename files simultaneously owned by another process.
Capture Fluentd logs
Fluentd marks its own logs with the fluent
tag. You can process Fluentd logs by using <match fluent.**>
(Of course, **
captures other logs) in <label @FLUENT_LOG>
. If you define <label @FLUENT_LOG>
in your configuration, then Fluentd will send its own logs to this label. This is useful for monitoring Fluentd logs.
For example, if you have the following configuration:
Then, Fluentd outputs fluent.info
logs to stdout like this:
Case 1: Send Fluentd Logs to Monitoring Service
You can send Fluentd logs to a monitoring service by plugins e.g. datadog, sentry, irc, etc.
Case 2: Use Aggregation/Monitoring Server
You can use out_forward
to send Fluentd logs to a monitoring server. The monitoring server can then filter and send the logs to your notification system e.g. chat, irc, etc.
Leaf Server Example:
Monitoring Server Example:
If an error occurs, you will get a notification message in your Slack notify
channel:
Deprecate Top-Level Match
You can still use v0.12 way without <label @FLUENT_LOG>
but this feature is deprecated. This feature will be removed in fluentd v2.
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Last updated