Common Log Formats
- Apache Access LogUse
format apache2
as shown below:<source>@type tailformat apache2tag apache.accesspath /var/log/apache2/access.log</source> - Apache Error LogUse a regular expression. See the
format
field in the following sample configuration.<source>@type tailformat /^\[[^ ]* (?<time>[^\]]*)\] \[(?<level>[^\]]*)\] \[pid (?<pid>[^\]]*)\] \[client (?<client>[^\]]*)\] (?<message>.*)$/tag apache.errorpath /var/log/apache2/error.log</source>Depending on your particular error log format, you may need to adjust the regular expression above. You can test your format using fluentd-ui's in_tail editor or Fluentular. - MaillogUse a regular expression. See the
format
field in the following sample configuration.<source>@type tailformat /^(?<time>[^ ]+) (?<host>[^ ]+) (?<process>[^:]+): (?<message>((?<key>[^ :]+)[ :])? ?((to|from)=<(?<address>[^>]+)>)?.*)$/tag postfix.maillogpath /var/log/maillog</source> - Nginx Access LogUse
format nginx
as shown below:<source>@type tailformat nginxtag nginx.accesspath /var/log/nginx/access.log</source> - Nginx Error LogUse the
format*
andmultiline_flush_interval
fields in the following sample configuration. Applications running under Nginx can output multi-line errors including stack traces, so the multiline mode is a good fit.<source>@type tailtag nginx.errorpath /var/log/nginx/error.logformat multilineformat_firstline /^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} \[\w+\] (?<pid>\d+).(?<tid>\d+): /format1 /^(?<time>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[(?<log_level>\w+)\] (?<pid>\d+).(?<tid>\d+): (?<message>.*)/multiline_flush_interval 3s</source>If you know your error log will only contain single lines, you can use the below simpler configuration with just aformat
.<source>@type tailformat /^(?<time>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[(?<log_level>\w+)\] (?<pid>\d+).(?<tid>\d+): (?<message>.*)$/tag nginx.errorpath /var/log/nginx/error.log</source> - GlusterFS Logs
Give us a shout on GitHub, Twitter or the mailing list. Better yet, we always welcome a pull request!
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is a open source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Last modified 3yr ago