Modifying LogFormat in Apache
Solution 1:
The IfModule directive is to take the configuration only if the module was loaded. To check which modules are loaded you can use
-
httpd -M -f path-to-config-file
using linux - and
httpd -t -D DUMP_MODULES
using windows
Example
[root@apachesrv bin]# httpd -M -f conf/httpd-vserver.conf
Loaded Modules:
core_module (static)
...
log_config_module (shared)
...
proxy_http_module (shared)
schema_module (shared)
Syntax OK
In this case you can see I am using the log_config_module so it will take (on my case) the config
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog "logs/access_log" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
</IfModule>
In order to catch the information you need you need to configure a log with something like:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Forwarded-For}i\"" combinedcustomized
And then change your access log to:
CustomLog logs/access.log combinedcustomized
EDIT:
On the apache doc you have the list of available parameters to log http://httpd.apache.org/docs/2.4/mod/mod_log_config.html