Pushing Logs from Software - Apache
This guide will present you with three non-intrusive ways to send logs to the Logs Data platform:
- ask Apache to pipe log entries directly to the platform.
- use syslog-ng to parse and send all of your logs
- setup filebeat with the Apache module
Apache access logs are very valuable. They show the activity of your visitors, page delivery time, code results, user agents that accessed your websites, etc. Logs Data Platform helps you to fully analyze this key information.
The default Apache log line looks like this:
This line already gives a lot of information but it can be difficult to extract really useful data from plain text logs. There are many ways to export your Apache logs: logstash, beats, graylog-collector, syslog-ng, rsyslog, gelf, or apache module.
Requirements
- the openssl package (as we are using it to send the logs securely)
- an activated Logs Data Platform account
- at least one Stream and its token
Instructions
Use Apache to send logs directly
NOTE: The following procedure has the advantage of a quick setup but is NOT recommended at all in production as it can block the Apache process in the case of heavy traffic. In production, please use a non-blocking solution like the second solution in this guide, or this one: Pushing Logs with a Forwarder - Filebeat (Linux).
Global Apache configuration
First, we will configure Apache2 to send all Virtual Hosts logs to one stream.
NOTE: If you have any log related configuration in your virtual hosts, you must remove them or head to the next section to add a specific virtual host configuration.
We use the CustomLog format directive to transform Apache logs in LTSV format and ship them to the Logs Data Platform with the proper OVHcloud token. Note that three fields are mandatory with the LTSV format; host, message, and time (in the RFC 3339 format). Refer to the examples below to learn how to fill in these fields. Please create the file /etc/httpd/conf-enabled/ldp.conf or /etc/apache2/conf-enabled/ldp.conf (it depends on your distribution) and insert the following:
If you want to send your logs to an additional stream, you would need to repeat this snippet and change the LogFormat name combined_ltsv of your new snippet to a new name.
Note that you will have to replace the address and the port of <your_cluster>.logs.ovh.com with the one you have been assigned to (check the Home page to retrieve it). Ensure that the full path of openssl is correct for your system or it won't work. Also ensure that your X-OVH-TOKEN is properly written. This tutorial only covers how to send your access logs to the Logs Data platform. To send your Error logs, you should configure your syslog template to send logs to Logs Data platform. Finally, check that you don't use any CustomLog option in your VirtualHost configuration since the VirtualHost configuration has precedence over global configuration.
You also need to modify the /etc/httpd/sites-enabled/000-default.conf or /etc/apache2/sites-enabled/000-default.conf file to ensure that the ErrorLog and CustomLog lines (shown below in yellow) are commented out:
VirtualHost configuration
If you want to only send logs from a specific VirtualHost, or send specific information about one VirtualHost, use this configuration to send logs to Logs Data platform:
This is what you see on Graylog when you send your logs. The logs are already nicely parsed and you can immediately launch specific searches on them:

Using a syslog-ng template
If you already have syslog-ng on your host and you want to leverage its features (log rotation, automatic reconnection, multiple destinations). Here are the configuration snippets allowing you to use this software.
Apache configuration
The configuration is pretty similar to the one used in the first part of this document. The only change is the path of the log file.
Syslog-ng configuration
To keep things brief, this extract has only the parts relevant to the access log file. The syslog-ng tutorial covers the configuration for any syslog file (like the error log file). This configuration is only valid for syslog-ng 3.8+.
Apache logs format
If you want to use your own log format and include some useful information here is a cheat sheet for you (note that the labels follow the field naming conventions).
The full list of logs formats that can be used in Apache is described here mod_log_config.html.
Using Filebeat
The latest releases of Filebeat have a dedicated module for Apache2. This solution is ready-to-use to configure and is more production-ready. The complete procedure of its installation is described on this page in the Apache logs use case.
Go further
Browse all the Logs Data Platform guides.
Browse the rest of the OVHcloud US documentation for guides on our other products and services.
Learn more about Logs Data Platform on the OVHcloud US website.