Welcome!

Java Authors: Sharon Barkai, Elizabeth White, Liz McMillan, Pat Romanski, Kevin Benedict

Related Topics: Java, XML, AJAX & REA, Apache

Java: Blog Post

JSON Logging in Apache and Nginx with Logentries

We’ll discuss configuring Apache and Nginx both to send JSON formatted logs

I'm often asked on calls with our customers what is the preferred format for log data being sent to Logentries. While we pride ourselves on being the Log Management tool that is easiest to setup and use, some very important advanced features of the platform are available for logs that are formatted into Key Value Pair (KVP) or JSON. Most applications and programing languages have the ability to change their logging format. With a little bit of work, you can unlock the full potential of our advancedsearch functions. Below we'll discuss configuring Apache and Nginx both to send JSONformatted logs and how to take advantage of the search functions, sharable dashboards, and reporting capabilities within the Logentries platform.

Apache
Within Apache2, the default format of the access and error log looks like this:

127.0.0.1 - - [11/Aug/2014:16:44:00 +0000] "GET / HTTP/1.0" 200 11783 "-" "ApacheBench/2.3"

This log entry definitely contains some very important information. But by spending only 5 minutes configuring Apache, the logging information will contain a lot more useful information.

Start out by editing the apache2.conf file for your site/server found in /etc/apache2. Add the following line of code to your LogFormat area (see screen shot below).

nt\":\"%{User-agent}i\", \"referer\":\"%{Referer}i\" }" leapache

Once this is configured, you now need to edit the default.conf for each site within your Apache configuration. In this case, we want to change the log type of access.log to leapache. For instance:

More Stories By Trevor Parsons

Trevor Parsons is Chief Scientist and Co-founder of Logentries. Trevor has over 10 years experience in enterprise software and, in particular, has specialized in developing enterprise monitoring and performance tools for distributed systems. He is also a research fellow at the Performance Engineering Lab Research Group and was formerly a Scientist at the IBM Center for Advanced Studies. Trevor holds a PhD from University College Dublin, Ireland.