Log rollover for IBM HTTP Server and the WebSphere plugin

By default both the IBM HTTP Server and the IBM WebSphere Plugin write their log lines to 3 files (access.log and error.log for IHS and http_plugin.log for the WebSphere plugin). In busy environments these files get big really fast. Luckily there’s the possibility to do log rotation and define a timespan (or a maximum size) after which a new log file is created. For IBM HTTP Server this process is well documented (do realise though the ‘-n’ option is not implemented in IHS as IHS is based on Apache 2.2 while this option was introduced in Apache 2.4). For the WebSphere plugin however it’s less well documented.

To do log rotation in the WebSphere Plugin, you can use the rotatelogs binary from IHS. The line to configure the log location can be found in the plugin-cfg.xml. By default this line looks (on Windows) something like:

<Log LogLevel="Error" Name="C:\IBM\WebSphere\Plugins/logs/IHServer01/http_plugin.log"/>

To implement log rotation it should look like:

<Log LogLevel="Error" Name="|C:/IBM/HTTPServer/bin/rotatelogs.exe C:/IBM/WebSphere/Plugins/logs/IHServer01/%Y-%m-%d-%H_%M_%S-http_plugin.log 86400"/>

If your webserver is managed by the Deployment manager, you’ll have to set this property in the WebSphere ISC under servers – webservers – <your webserver> – Plug-in properties – Plug-in logging.

Look here for more information and other logging possibilities.

With the lines above you’re log will rotate daily. It doesn’t however delete old logs. You’ll need to schedule a job to delete old files through cron or task scheduler. Below are two scripts to delete these files in Windows (after 30 days)

.bat script:
forfiles -p "C:\IBM\HTTPServer\logs" -s -m access*.log -d -30 -c "cmd /c del @path"
forfiles -p "C:\IBM\HTTPServer\logs" -s -m error*.log -d -30 -c "cmd /c del @path"
forfiles -p "C:\IBM\WebSphere\Plugins\logs\IHServer01" -s -m *.log -d -30 -c "cmd /c del @path"
$old = 30
$now = Get-Date
$ihslogs = "c:\IBM\HTTPServer\logs"
$pluginlogs = "c:\IBM\WebSphere\Plugins\logs"

Get-ChildItem -Path $ihslogs -Recurse -Include "access_*.log", "error_*.log" | Where-Object {-not $_.PSIsContainer -and $now.Subtract($_.CreationTime).Days -gt $old } | Remove-Item -force
Get-ChildItem -Path $pluginlogs -Recurse -Include "*http_pluginlog.log" | Where-Object {-not $_.PSIsContainer -and $now.Subtract($_.CreationTime).Days -gt $old } | Remove-Item -force