Apache Error Log Explained - Stackify (2024)

By: Eric

| March 17, 2023

Apache Error Log Explained - Stackify (1)

Many online applications use a web server as the primary point of contact for their clients. At least43% of those systemsare running theApache HTTP Server. If you’re responsible for one of those systems, you need to work with the Apache error log.

Apache provides comprehensive logging via several different files, but theerror logis the most important. You can even say Apache misnamed the file because it contains more than just errors. Apache records a large amount of diagnostic information in the error log. You have control over where it stores the messages and what information goes into them.

Let’s dive in and see how you can use the Apache error log to watch your web server and improve its reliability and resiliency.

Configuring the Apache error log

You configure the error log with a set of directives that, like all Apache configuration values, you place in plain text files. I’ll be referring to the latest release of the web server in this post, which is 2.4 as of this writing.’

You can find details for how to set up configuration files for Apachehere. I’ll cover the settings for the Apache error log in this post.

Apache error log location

TheErrorLogconfiguration setting controls the location of the Apache error log file. Here’s the default setting for the Apache2 docker image:

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog /proc/self/fd/2

This configuration directs the logs to standard error, which is a sensible setting for mostDockerenvironments.

You can enter any valid filename and the Apache will use it.

ErrorLog "/var/log/apache2/error.log"

If the file already exists, Apache will append new messages to it. So if you want to rotate log files to keep them from getting too large, you need to set something up on your own.

You can also send log messages to a Syslog server. Instead of a filename, use theSyslogdirective.

ErrorLog syslog

The Syslog option has several different choices about the logging facility and the application name. You can find the detailshere.

Finally, you can direct logs to a Linux command.

ErrorLog "|/usr/local/bin/httpd_errors"

Apache interprets the pipe character to mean it should pipe the messages to the specified command.

Apache logging level

The Apache error log has a logging level that filters the messages sent to the log. You specify the level with theLogLevelsetting.

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

The Apache documentation describes the levels this way:

LevelDescription
emergSystem is unusable
alertAction must be taken immediately
critCritical conditions
errorError conditions
warnWarning conditions
noticeNormal, but significant conditions
infoInformational messages
debugDebugging messages
trace1 – trace8Trace messages with gradually increasing levels of detail

Let’s make a quick comparison of thewarnanddebuglevels. I’ll request a valid page and then an invalid one with each level.

Apache logs nothing for a single page request inwarnlevel.

But, here’s the same request indebuglevel:

[Fri Feb 01 22:03:08.318615 2019] [authz_core:debug] [pid 9:tid 140597881775872] mod_authz_core.c(820): [client 172.17.0.1:50752] AH01626: authorization result of Require all granted: granted
[Fri Feb 01 22:03:08.319124 2019] [authz_core:debug] [pid 9:tid 140597881775872] mod_authz_core.c(820): [client 172.17.0.1:50752] AH01626: authorization result of <RequireAny>: granted
[Fri Feb 01 22:03:08.319709 2019] [authz_core:debug] [pid 7:tid 140597881775872] mod_authz_core.c(820): [client 172.17.0.1:50750] AH01626: authorization result of Require all granted: granted
[Fri Feb 01 22:03:08.320285 2019] [authz_core:debug] [pid 7:tid 140597881775872] mod_authz_core.c(820): [client 172.17.0.1:50750] AH01626: authorization result of <RequireAny>: granted
[Fri Feb 01 22:03:08.320970 2019] [core:info] [pid 7:tid 140597881775872] [client 172.17.0.1:50750] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico
[Fri Feb 01 22:03:08.960056 2019] [authz_core:debug] [pid 7:tid 140597873383168] mod_authz_core.c(820): [client 172.17.0.1:50750] AH01626: authorization result of Require all granted: granted
[Fri Feb 01 22:03:08.960641 2019] [authz_core:debug] [pid 7:tid 140597873383168] mod_authz_core.c(820): [client 172.17.0.1:50750] AH01626: authorization result of <RequireAny>: granted
[Fri Feb 01 22:03:08.961235 2019] [core:info] [pid 7:tid 140597873383168] [client 172.17.0.1:50750] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico
[Fri Feb 01 22:03:09.025752 2019] [authz_core:debug] [pid 7:tid 140597864990464] mod_authz_core.c(820): [client 172.17.0.1:50750] AH01626: authorization result of Require all granted: granted
[Fri Feb 01 22:03:09.026205 2019] [authz_core:debug] [pid 7:tid 140597864990464] mod_authz_core.c(820): [client 172.17.0.1:50750] AH01626: authorization result of <RequireAny>: granted
[Fri Feb 01 22:03:09.026647 2019] [core:info] [pid 7:tid 140597864990464] [client 172.17.0.1:50750] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico
[Fri Feb 01 22:03:13.885995 2019] [authz_core:debug] [pid 7:tid 140597856597760] mod_authz_core.c(820): [client 172.17.0.1:50750] AH01626: authorization result of Require all granted: granted

You can see that theauthz_coremodule is very noisy. If you want to watch the logs for other modules while filtering out messages from it, you can set its log level explicitly.

LogLevel debug authz_core:info

Thissetting sets the server fordebug,but explicitly filters theauthz_coreback to info.

Let’s try the page request again.

[Fri Feb 01 22:07:57.154391 2019] [core:info] [pid 10:tid 140284200093440] [client 172.17.0.1:50756] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico
[Fri Feb 01 22:07:57.808291 2019] [core:info] [pid 8:tid 140284216878848] [client 172.17.0.1:50758] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico
[Fri Feb 01 22:07:57.878149 2019] [core:info] [pid 8:tid 140284208486144] [client 172.17.0.1:50758] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico

We can see that the real problem with my web server is no favicon and my browser is very upset about it.

Apache error log format

You can change the format of log messages too. So far, I’ve been using the default format. You specify the message composition with theErrorLogFormatsetting.

Let’s try a different setting and look at the difference. I’ll use this example from theApache docs.

ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"

Here’s what a request looks like now:

[Fri Feb 01 22:17:49 2019][info] [pid 9] core.c(4739): [client 172.17.0.1:50764] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico

Let’s go over how this format works. The setting is a format string with parameters corresponding to fields in a logging event.

Here are the fields we used above:

ItemExplanation
[%t]timestamp for the message
[%l]level of the message
[pid %P]process pid
%Fsource code file and line
%Eerror status code and string
%aclient IP address and string
%Mthe log message

The sample log message lacks a message for the%Esetting, so it’s missing. The Apache error log doesn’t fill missing parameters. It omits them.

You can specify different formats for new connections and new requests. A connection is when a new client connects to the server. A request is a message asking for a resource, such as a page or an image. Apache uses connection and request formats when a new client connects or makes a web request. It logs a message indicating that a client has connected or registered a new request.

Let’s add a newLogFormatfor a connection.

ErrorLogFormat connection "[%t] First time: [pid %P] %F: %E: [client %a]"
ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"

The new entry prints a “First time:” message along with the fields we’ve defined for our standard log format. But we had to omit%Msince there’s no error message corresponding to a new connection.

Now, we’ll make our single-page request again.

[Fri Feb 01 22:44:09 2019] First time: [pid 9] [client 172.17.0.1:50770]
[Fri Feb 01 22:44:09 2019] [info] [pid 9] core.c(4739): [client 172.17.0.1:50770] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico

We see the initial connection message and then the failed request for a favicon.

You can specify more than one connection or request log entry if you want to print information in separate listings.

Apache request tracking

You can take logging messages for new connections and requests one step further. The Apache error log will generate a unique identifier for every new request or connection. You can use this value to collate log entries. Use the%Lfield for identifiers.

So let’s change our configuration to reflect a new entry for each connection and request. Then, we’ll add the IDs to the standard log message.

ErrorLogFormat connection "[%t] New connection: [connection: %{c}L] [client %a]"
ErrorLogFormat request "[%t] New request: [connection: %{c}L] [request: %L] [pid %P] %F: %E: [client %a]"
ErrorLogFormat "[%t] [%l] [C: %{c}L] [R: %L] [pid %P] %F: %E: [client %a] %M"

So in the connection entry, we generate a connection identifier with%{c}L. In the request entry, we print the connection ID and then generate a request ID with%L. Finally, we add the IDs to each standard log entry.

Here is a page request:

[Sat Feb 02 00:30:55 2019] New connection: [connection: j8BjX4Z5tjk] [client 172.17.0.1:50784]
[Sat Feb 02 00:30:55 2019] New request: [connection: j8BjX4Z5tjk] [request: p7pjX4Z5tjk] [pid 8] [client 172.17.0.1:50784]
[Sat Feb 02 00:30:55 2019] [info] [C: j8BjX4Z5tjk] [R: p7pjX4Z5tjk] [pid 8] core.c(4739): [client 172.17.0.1:50784] AH00128: File does not exist: /usr/local/apache2/htdocs/favicon.ico
[Sat Feb 02 00:30:55 2019] New request: [connection: j8BjX4Z5tjk] [request: ACtkX1Z5tjk] [pid 8] [client 172.17.0.1:50784]
[Sat Feb 02 00:30:55 2019] [info] [C: j8BjX4Z5tjk] [R: ACtkX1Z5tjk] [pid 8] core.c(4739): [client 172.17.0.1:50784] AH00128: File does not exist: /usr/local/apache2/htdocs/foo.gif
[Sat Feb 02 00:30:55 2019] New connection: [connection: gTxkX8Z6tjk] [client 172.17.0.1:50786]
[Sat Feb 02 00:30:55 2019] New request: [connection: gTxkX8Z6tjk] [request: 5TVkX8Z6tjk] [pid 8] [client 172.17.0.1:50786]
[Sat Feb 02 00:30:55 2019] [info] [C: gTxkX8Z6tjk] [R: 5TVkX8Z6tjk] [pid 8] core.c(4739): [client 172.17.0.1:50786] AH00128: File does not exist: /usr/local/apache2/htdocs/bar.gif
[Sat Feb 02 00:30:55 2019] New request: [connection: gTxkX8Z6tjk] [request: wvRoX3Z6tjk] [pid 8] [client 172.17.0.1:50786]
[Sat Feb 02 00:30:55 2019] [info] [C: gTxkX8Z6tjk] [R: wvRoX3Z6tjk] [pid 8] core.c(4739): [client 172.17.0.1:50786] AH00128: File does not exist: /usr/local/apache2/htdocs/foobar.gif
[Sat Feb 02 00:30:55 2019] New request: [connection: gTxkX8Z6tjk] [request: i/JtX9Z7tjk] [pid 8] [client 172.17.0.1:50786]

Now we can see each connection and request as they’re created. I added a few bad image tags to the request page to generate extra traffic.

Monitoring web applications

Apache is a mature web server with powerful tools for monitoring. You can configure its robust logging in a way that suits yourapplication and monitoringneeds.

You can collect Apache error logs with Stackify’sRetrace. Configure the Stackify agent to watch your weblogs by following the instructionshere.

Related posts:

  • A Guide to Logging in Azure Functions
  • Retrace Log Management: Logs, Errors and Code Level Performance
  • PHP Error Handling Guide
  • NLog vs log4net vs Serilog: Compare .NET Logging Frameworks

Improve Your Code with Retrace APM

Stackify's APM tools are used by thousands of .NET, Java, PHP, Node.js, Python, & Ruby developers all over the world.
Explore Retrace's product features to learn more.

  • App Performance Management
  • Code Profiling
  • Error Tracking
  • Centralized Logging

Learn More

Apache Error Log Explained - Stackify (7)

Author

Eric

More articles by Eric

Apache Error Log Explained - Stackify (2024)

FAQs

Apache Error Log Explained - Stackify? ›

The Apache error log has a logging level that filters the messages sent to the log. You specify the level with the LogLevel setting. # LogLevel: Control the number of messages logged to the error_log.

How to read Apache error logs? ›

On a Linux server, you can access Apache error logs from var/log/apache2/error. log. You can then log out the errors from the error log file by writing the following command: sudo tail -f /var/log/apache2/error. log.

How do I troubleshoot common Apache errors? ›

In this article, I will be outlining some tips which can be used when analyzing and remediating the most common issues encountered in Apache.
  1. Verify your Apache HTTP Server configuration. ...
  2. Use the latest version of Apache HTTP Server. ...
  3. Apache HTTP Server logs. ...
  4. Use the mod_log_forensic module. ...
  5. Use the mod_whatkilledus module.

How to clear Apache error log? ›

The command sudo bash -c 'echo > /var/log/apache2/error. log' is used to clear the contents of the Apache2 error log file.

What is the default Apache error log format? ›

Apache uses the Common Log Format (CLF) by default, but you can specify your own format string to change the fields included in each log. You can also use the CustomLog directive to change the location of the log file.

How do I check error logs? ›

Click Start > Control Panel > System and Security > Administrative Tools. Double-click Event Viewer. Select the type of logs that you wish to review (ex: Windows Logs)

How do you read logs? ›

The data contained within a LOG file is regular text. As a result, you can open a . LOG file in any basic text editor. By default, Windows uses Notepad to open LOG files.

What are the default error pages for Apache? ›

The Apache web server provides a default set of generic error pages for 404, 500, and other common Apache errors. However, creating custom error pages allows you to: Continue your branding on these pages. Integrate their design into the look and feel of your website.

How do I know if Apache is running properly? ›

Using the apachectl status Command. An additional method that enables you to check the Apache status is by using the apachectl status command in your terminal. This command is typically available on most Apache installations and provides various options to manage and monitor the web server.

How to check Apache 500 error? ›

We can use strace to attach to a running Apache process and trace its system calls to identify the root cause of the 500 error. If you don't have strace installed, you can install it using your system's package manager.

What is Apache log error 400? ›

A “400 Bad Request” error means the server cannot process the request due to client-side issues. A “404 Not Found” error, on the other hand, indicates that the server cannot find the requested resource. In short, a 400 error is about a bad request, while a 404 error is about a missing resource.

Can I delete an Apache log? ›

If you delete the file while apache is not running, it'll just create it when starting. If you prevent apache from being able to write to it, the server will simply not start, if I recall correctly.

How to change Apache log level? ›

Apache logging level

You specify the level with the LogLevel setting. # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg.

How to read Apache error log? ›

Apache Errors Logs Location
  1. On Red Hat, CentOS, or Fedora Linux, the access logs can be found in the /var/log/httpd/error_log by default.
  2. On Debian and Ubuntu, you can expect to find the Apache logs in the /var/log/apache2/error.log.
  3. FreeBSD will have the Apache server access logs in /var/log/httpd-error. log file.
Nov 19, 2021

What is the size limit of Apache error log? ›

With standard configuration, Apache will check daily if the log file size is over 1 MB. If the file does exceed this limit, it will be rotated. You can learn how to change the default behavior following this tutorial. This configuration will rotate the logfile whenever it reaches a size of 5 megabytes.

What is the default rotation of Apache logs? ›

By default, at least on Ubuntu apache2 is set to rotate logs every 14 days. You will need to check storage capacity if you are going to keep logs on box for a period. You may want to consider shipping these to a SIEM.

How to see all errors in Apache PHP? ›

The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

How to read error logs in Linux? ›

You can also view logs via dmesg, which prints the kernel ring buffer and sends you to the end of the file. From there, you can use the command dmesg | less to scroll through the output. If you want to view log entries for the user facility, you need to issue the command dmesg –facility=user.

How to read Apache Tomcat logs? ›

To collect Tomcat logs, you first need to enable logging. Logging in Tomcat is handled by the Java Utility Logging Implementation, also known as JULI. JULI is enabled by default, and you can perform this configuration using the logging configuration file option -Djava. util.

How do I read Apache server status? ›

A machine-readable version of the status file is available by accessing the page http://your.server.name/server-status?auto . This is useful when automatically run, see the Perl program log_server_status , which you will find in the /support directory of your Apache HTTP Server installation.

Top Articles
Healthy Lifestyles, Healthy Outlook
Apple M1 Max vs Intel 12th-gen Alder Lake processors: Which one's better?
7 C's of Communication | The Effective Communication Checklist
Cottonwood Vet Ottawa Ks
J & D E-Gitarre 905 HSS Bat Mark Goth Black bei uns günstig einkaufen
Kokichi's Day At The Zoo
Ati Capstone Orientation Video Quiz
Hertz Car Rental Partnership | Uber
Obituary (Binghamton Press & Sun-Bulletin): Tully Area Historical Society
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Mail Healthcare Uiowa
Jet Ski Rental Conneaut Lake Pa
Sitcoms Online Message Board
Wnem Radar
Springfield Mo Craiglist
The most iconic acting lineages in cinema history
Illinois Gun Shows 2022
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
360 Tabc Answers
Foxy Brown 2025
Airrack hiring Associate Producer in Los Angeles, CA | LinkedIn
Uta Kinesiology Advising
Defending The Broken Isles
Speedstepper
Jail Roster Independence Ks
Autopsy, Grave Rating, and Corpse Guide in Graveyard Keeper
Sadie Sink Doesn't Want You to Define Her Style, Thank You Very Much
Hisense Ht5021Kp Manual
The Bold And The Beautiful Recaps Soap Central
The Complete Guide To The Infamous "imskirby Incident"
Sams La Habra Gas Price
20 Best Things to Do in Thousand Oaks, CA - Travel Lens
Ludvigsen Mortuary Fremont Nebraska
Sc Pick 4 Evening Archives
Join MileSplit to get access to the latest news, films, and events!
M Life Insider
Dispensaries Open On Christmas 2022
Other Places to Get Your Steps - Walk Cabarrus
The best specialist spirits store | Spirituosengalerie Stuttgart
ESA Science & Technology - The remarkable Red Rectangle: A stairway to heaven? [heic0408]
Mynord
Joblink Maine
City Of Irving Tx Jail In-Custody List
Www.homedepot .Com
What Time Do Papa John's Pizza Close
Diablo Spawns Blox Fruits
Craigslist Monterrey Ca
Craigslist Charlestown Indiana
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 6460

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.