DULMEN.net   Follow me on Facebook Contact DULMEN.net  

RotateLogs - Programming@DULMEN.net

RotateLogs
This Windows system tray application stops e.g. the Apache webserver, archives the log files and restarts the webserver on a pedefined schedule.
RotateLogs uses 7Zip to compress the logs. 7-Zip is licensed under the GNU LGPL license. More info can be found at www.7-zip.org.
 
Features
-Tested on Apache webserver
-Schedule can be set to daily, weekly or monthly
-Compresses the old logfiles using 7za.exe (included)
-Starts and stops the webserver services (with a predefined commandline)
-Optionally writes a logfile with executed tasks
 
Description
At home I have a Windows server running Apache v2.x HTTPD. On this server DULMEN.net is hosted. As most server applications Apache HTTPD logs all data requests and errors in log files. These log files keep growing until they are manually cleared or removed. I always forget this kind of simple tasks and after removing a log file of more than 25Gb I decided to automate this task.

RotateLogs automatically stops the Apache HTTPD service, renames the log files by adding the date in front of the filename, archives the log files into a compressed file using the commandline version of 7Zip (included) and restarts the Apache HTTPD service. All this following a predefined schedule or manually from the Windows system tray menu.

The first time RotateLogs is started it elevates itself by registering with the highest privileges. The Windows User Account Control (UAC) will prompt for confirmation. As long as it is started from the same folder this confirmation is not needed after the first run.

If an error occures during the rotation of the Apache log files the icon in the system tray is changed (red circle with x is added to the icon). Errors are loged in the RotateLogs log file which can be opened from the main window or the system tray menu. See the error codes below.
If all went well a green circle with a check mark is added to the system tray icon.

The configuration file can also be opened from the main window or the system tray menu. After editing the configuration file Refresh needs to be choosen from the system tray menu to activate the new settings.
 
Screenshots
RotateLogs log file, main window and tray menu
 
Error codes
RotateLogs.exe Error codes
101Unable to stop service
102Unable to start service
103No log files found matching the specifications
104Compressed file not found after creation
201Error executing server stop command
202Error executing server start command
7za.exe Errorlevel codes
0Success: Successful operation
1Warning: Non fatal error(s) occurred
2FatalError: A fatal error occurred
3CRCError: A CRC error occurred when unpacking
4LockedArchive: Attempt to modify an archive previously locked
5WriteError: Write to disk error
6OpenError: Open file error
7UserError: Command line option error
8MemoryError: Not enough memory for operation
9CreateFileError: Create file error
255UserBreak: User stopped the process
ErrorError executing compression command (generated by AHK)
 
Commandline options
No command-line options available.
 
Configuration file settings
[ApplicationOptions]
Writelog Create application log (1=On, 0=Off, Default=On)
MaxLogSizeKb Max log file size in Kb(Default=100)
[ServerOptions]
ServerName Server name (Default=Apache)
ServerProgram Server application (Default=C:\SERVER\Apache2.2\bin\httpd.exe)
ServiceName Service name (Default=Apache2.2)
ServerStopCmd Service stop command parameters (Default= -w -n "Apache2.2" -k stop)
ServerStartCmd Service start command parameters (Default= -w -n "Apache2.2" -k start)
[LogOptions]
ServerLogsDir Server log files directory (Default=C:\SERVER\Apache2.2\Logs)
LogsDestinationDir Log files destination directory Default=C:\SERVER\Apache2.2\Logs)
AccessLogName String in filename access log (Default=Access)
ErrorLogName String in filename error log (Default=Error)
[TimerOptions]
DailyWeeklyMonthly Rotate frequency (D=Daily, W=Weekly, M=Monthly, Default=M)
DayNumber Day of week (1=Sun..7=Sat) OR Day of month (01..31, Default=01)
HourNumber Hour of day (00..23, Default=02)
 
Version history
v1.0 Initial setup
v1.1 Added administrator rights request on startup (only once)
 
Known bugs
No known bugs.
 
Future enhancements
None.
 
Download
Please read the legal notice first, allthough you probably heard it before :)


Copyright 2018 DULMEN.net. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY DULMEN.net ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL DULMEN.net OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of DULMEN.net.


You can download RotateLogs as a compressed folder containing all files needed. No need to install the software, just unzip, adapt the configuration file RotateLogs.ini and run RotateLogs.exe.
RotateLogs is free for personal and bussiness use and is free to distribute as is as long as the program is not altered and accompanied with the RotateLogs text file.

VersionFileSize
v1.1RotateLogs_v1.1.zip776,14 KB (794767 bytes)
v1.1RotateLogs_v1.1.7z624,08 KB (639057 bytes)
v1.0RotateLogs_v1.0.zip775,63 KB (794247 bytes)
v1.0RotateLogs_v1.0.7z621,18 KB (636085 bytes)
 
 
Share
DULMEN.net © v8 2018 - Designed & written by Arno van Dulmen