Hurry! Try our new Interactive Courses for FREE. 🥳   🚀
Written By:
iamabhishek
5 minute read
ApacheHowToLogging

How to Change Log Level of Apache Web Server

Posted in Cloud   LAST UPDATED: SEPTEMBER 7, 2021

When we host our website using the Apache Webserver, we generally don't care about the log level of the Apache web server, which is set as notice log level, which means, all the logs for emerg, alert, crit, error, warn and notice are logged in either the access_log or error_log files.

Before we learn how to change the log level, let's first see what are the various log levels that are available in the Apache webserver. In the table below we have listed all the log levels, in order of decreasing significance, which means, the first one is most important and the last one is least.

Level Description
emerg Shows emergencies that may have rendered the server unusable.
alert Shows errors that must be solved immediately.
crit Shows critical conditions.
error Shows error conditions.
warn Shows warning conditions, which are generally not errors, but issues that must be solved.
notice Shows normal notices, information that can help fix future issues may be because of deprecated syntax, or non-declared variables, etc.
info Shows informational messages.
debug Shows debug level messages which can be used by developers to debug what is happening in the code.
trace1 Trace messages.
trace2 Trace messages.
trace3 Trace messages.
trace4 Trace messages.
trace5 Trace messages.
trace6 Trace messages.
trace7 Trace messages.
trace8 Trace messages.

In the above table, we have all the log levels. When a particular log level is used, all the logs of more significance, those are the ones that lie above it in the table, are printed in the log file.

For example, if we set the log level as info, then, notice, warnings, error, and other higher significance logs are printed in the log file.

How to change Log level in Apache Webserver?

To change the log level for the Apache webserver, we have to add the below line of code in the Apache webserver configuration file:

LogLevel alert rewrite:warn

In the above line, we have set the log level to warning.

Below we have a sample Apache configuration file, where we have also used the ErrorLog configuration to change the log file location too, to a custom location.

<VirtualHost *:80>
    RewriteEngine On
    LogLevel alert rewrite:warn
    ErrorLog "C:\Users\.....\Desktop\log.txt"
    ServerName .....
    DocumentRoot ....
    <Directory  ....>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

FAQ:

Here are some important FAQs related to the Apache server log level.

What is the best log level for Apache Webserver?

By default, the apache web server is set to notice log level, which means all the logs above this log level will be printed in the log files. That leads to two problems, one, the large size of log files, second, the apache webserver has to do a lot more work printing all these additional logs, which can make the webserver slow.

Hence the right or the best or the appropriate log level should be error log level because then all the issues that need fixing will be logged in the log files, while warnings and notices will be skipped.

Why change the Log level of Apache Server to debug?

As a developer, you may want to set the log level of the Apache webserver to debug, to print logs in your application code to debug any error. Proper logging, can help developers debug issues easily in the application code.

Can we use the .htaccess file to change the log level of the Apache Web server?

No, we cannot use the .htaccess file to change the log level. To change the log levels, we have to configure it in the Apache webserver config file.

Conclusion:

I hope this article helps you in understanding how the log level can be changed for the Apache webserver, what are the various log levels available, and what is the right configuration when it comes to log levels.

If you face any problem, please share it with us in the comment section below.

You may also like:


IF YOU LIKE IT, THEN SHARE IT

RELATED POSTS