Apache has been in the market since 1995 and is the foremost technology driving the web. Today, most companies are using Apache servers for their business. Different servers work differently and come with different features and functionalities. Some servers maintain server logs for easy debugging. Understanding the working of the server is crucial.
Apache error logs hold all the errors within the server while receiving or processing the request. Admin users can access these logs and troubleshoot them for instant fixes.
These logs will give you valuable information regarding the traffic coming to your application, occurring errors, and performance. This article will focus on Apache web server logs, how to read and view them, and how to analyze them.
What Are Apache Logs?
Apache server stores all the information about every activity within the server in the text file called Apache logs. These logs help get valuable insight into what resources are accessed and freed. Also, the logs contain the information about who accessed those resources for how much time and provide all the metrics related to it.
Not only this, you will get all the information related to all the errors that occurred. These logged errors are very useful by the admin people who look into fixing those errors and find the root cause to eliminate the chances of occurring that error again.
Well, there is not a single process of Apache logging process. It is done in many phases, such as storing the logs at a specific location for future reference, analyzing and parsing those logs for getting necessary information, and generating the graph for a better visual representation to get a better understanding. There is not a single type of log that Apache has maintained. But here, we are mainly focusing on Apache2 error logs.
What Is the Apache Error Log?
If you cannot find what is going wrong within your server and throw errors repeatedly, it will lose its reliability. For easy and smooth working of the servers, we must store the information about the errors impacting the server's performance.
Thus, Apache has error logs that are stored at a specific location. The server admin sets up these log files and other details such as the size of the file, error time, type of error, error message for easy troubleshooting, etc.
These logs are kept on creating and stored at that location, making them available for future use. You must know where these errors are stored, how to access them and use the data stored within them.
Apache Error Log Location
If you are not aware of the error logs' location, it will take more time to get to the root cause. It is better to maintain a sheet and keep the location for easy reference. The location of the error files may differ depending on the type of operating system you are working on. We have mentioned the error logs' location or different operating systems below.
- The access logs on Red Hat, CentOS, or Fedora Linux can be found in the /var/log/httpd/error_log by default.
- On Debian and Ubuntu, you can expect to find the Apache logs in the /var/log/apache2/error.log
- FreeBSD will have the Apache server access logs in /var/log/httpd-error.log file.
Also, you can configure the error logs at your choice of location using the ErrorLog directive, as shown below.
ErrorLog "/var/log/httpd-error.log"
Apache Error Log Format Configuration
For creating new error logs, you can configure them as per your requirement and in your choice of format for easy debugging. You can use the ErrorLogFormat element of Apache to configure the error logs, as shown below.
ErrorLogFormat “[%{u}t] [%-m:%l] [pid %P:tid %T] [client\ %a] %M”
The above line will generate the error log entry within the Apache server, as shown below.
[Wed Nov 10 10:21:23.811033 2021] [core:error] [pid 22308:tid 3212342123] [client 10.1.2.3] File does not exist: /usr/local/apache2/htdocs/favicon.ico
Below, we have mentioned the formatting options you can use while configuring your error log.
- %{u}t – the current time with microseconds,
- %-m – the module that has created the error,
- %l – the level of the log event,
- %P – process identifier,
- %T – thread identifier,
- %M – the actual log message.
Log Levels
As we have mentioned, the (%l) specifies the level of the log event. The LogLevel directive helps you mention the log messages' level per module. It is also necessary to consider this option very well and understand what each level means. For example, suppose we want to set the main log level of the events to the info level and include the error level only for the rewrite module; then, you can set it using the below directive, as shown below.
LogLevel info rewrite:error
We have the following log levels in Apache.
- emerg
- alert
- crit
- error
- warn
- notice
- info
- debug
- trace1 – trace8
The emerg level states that the server is currently unstable in the above list, while the trace level states the low-level error messaging that you can ignore. But, emergency errors need to be treated as a priority.
How to View Apache Error Logs
You can run the commands on the command-line interface to get the information from the access log, as shown below.
sudo tail -100 /var/log/apache2/error.log
It might be possible that you have a different location for the error logs, so make sure you know the exact path.
The following tutorial can be used to view Apache error logs in Linux distributions including Ubuntu, CentOS, and debian.
Conclusion
There is no single task that goes on within servers. There are high chances that any task might fail and create some errors at the time of the day. So, how do you check what error has occurred and at what time? To make this search more manageable, Apache has error logs where all the details regarding the errors are stored for an easy debugging process. You can go through the entire log and look for specific error that has impacted the work.
The proper error format makes the troubleshooting more manageable and more efficient. Once to get hold of the issue, you can fix it as soon as possible.