Apache Logs:
The Logs of Apache server is more useful to maintain the webserver effectively. usually we have 2 kinds of logs that is access log and error log.Error logs are very useful for troubleshooting process.
Some important logging Directives of Apache
1.ErrorLog
2.LogLevel
3.LogFormat
4.CustomLog
5.PidFile
* Errorlog —> It Defines the file path to which the error logs of the server are to be store
Syntax:
ErrorLog file-path|syslog[:facility]
Their is two different method to mention the error log file in apache. By default the ErrorLog directive will be appear as
ErrorLog logs/error_log // here the file path is given as relative path to the server root
we can change the error log file path as user defined
Method 1
Example: ErrorLog /var/log/httpd/error_log
In the above example the file-path of error log is given as absolute path as user defined.
If the error log file path is start with a pipe symbol “|” means then it consider as a command to generate and handle the error log. for example
ErrorLog ”|/usr/sbin/rotatelogs /var/log/httpd/error_log 100M “
In the above example the rotatelogs command which comes after the pipe symbol will handle the error log file by rotating the error log if it reach’s the 100 MB in size.
Method 2
Instead of using file name in ErrorLog directive using syslog will enable the logging in apache
Example: ErrorLog “syslog:user”
while using syslogd you need to put the user name and log file path in /etc/syslog.conf file and kindly restart the syslog service
* LogLevel —> It Controls the verbosity or no of messages to be logged in error log file.
Syntax:
Loglevel level
The available loglevels are
emerg —> It means the emergency, server is not available ex: (28)No space left on device:
warn —> This is for Warning type of alert ex: child process 29960 still did not exit, sending a SIGTERM
error —> It specify the scripting errors ex: file does not exist
info —> information from server to the admin ex: server reached max clients
notice —> some Significant condition like service restarting
debug —> Debug level Messages like opening of config file
crit —> This is for critical condition ex: configuration error: couldn’t check user.
alert —> This for alert to take action immediately ex:getpwuid: couldn’t determine user name from uid
The default log level in apache is warn.
*LogFormat —> It will specify the access logformat, we can modify as per our needs
Syntax:
LogFormat “format” name
By Default the Log format in apache configuration file looks like as below
LogFormat “%h %l %u %t \”%r\” %>s %b”
The LogFormat directive gives logging format for access log, we can define the Logformat as per our needs.
Example:
LogFormat “%h %l %u %t %r %s %b %{Referer}i \”%{User-Agent}i\”” combined
CustomLog logs/access_log combined
In this example the log format defined as per the user needs and a nick name combined is given to the format which is used in CustomLog Directives as showned in above example
where h-host or IP , l-Client Identity , u-client username if have HTTP authentication , t-time and date ,r-Request content(requested page) , s-response code for the request , b-size of the data return to the client in bytes,i- User info like accessed url, browser, os etc
* CustomLog —> It logs the client request information on the server in the given location
Syntax:
CustomLog file|pipe format|nickname [env=[!]environment-variable]
In syntax first argument (file) is the location of the log, pipe is already seen in ErrorLog and 2nd argument is nickname mentioned in logformat, we can mention logformat here also, and the third argument is optional Which is used to record the particular log in separate file like logging request for gif images alone, It will be done by using SetEnvIf directive
Example: CustomLog logs/access_log combined
The above example shows the reative path of access log file and combined is the log format nick name as mentioned earlier in Logformat Directive. we can also give user defined absolute path to the access log as like below
CustomLog /var/log/httpd/access_log combined
This shows the absolute path of the access log file.
* PidFile —> To Specify the location to store the process id of the Deamon
Syntax: PidFile filename
The default pid file in apache is mentioned as
PidFile logs/httpd.pid
This file stores the process id of our apache service .
Example:
PidFile /var/run/apache.pid
In this example we changed the pid file path as per our wish.