Browse
 
Tools
Rss Categories

Cleaning Up Log Folders

Reference Number: AA-01911 Views: 3765 0 Rating/ Voters

Introduced with LumenVox version 12.0 was a set of features allowing users to configure extended logging parameters, which can be used to modify the number of backup copies of a log file that are maintained as well as the size of each.  A new feature was also added that allowed log files to be organized into sub-folders based on the current date, so that if users wanted to collect a large amount of log data over a number of days, this could be done in an orderly manner.

In previous versions, log files were of a fixed size, and there was only a single backup copy of each maintained. These files were all logged into the same fixed folder location, which meant that the files could only ever grow to a fixed, finite size on disk.

With the changes introduced with version 12.0, logging now offers much more flexibility to users. but also creates the possibility to create a lot of large log files each day, where ultimately this would fill up a hard drive, unless correctly managed.

This article describes some useful scripts that can be configured to clean up log files and folders after a configurable number of days.


Configuring Event Logging

A new configuration file, called "logs.conf" can be used to specify how logging should be performed. Within this configuration file, the MAX_LOG_FILE_SIZEMAX_LOG_BACKUPS and USE_EXTENDED_LOG_PATH options are available.

Of particular interest to this article is the USE_EXTENDED_LOG_PATH option, which causes log files to be recorded in sub-folders based on the current date, so for example if today was the 20th of November 2013, then the folder that would contain the log files would be in the /2013/11/20/ sub-folder below the regular logs folder.  Tomorrow, on the 21st, a new folder will be created and logs will be written to there, leaving the ones from today preserved for as long as desired.

In addition, the current level of logging_verbosity that is configured for LumenVox services has a large impact on the amount of information set to the logs. Generally, the higher the verbosity settings, the more information will be recorded, and the quicker that log files will be filled.

It is important to note that the default configuration settings will continue to behave as in versions prior to 12.0, so this cleanup may not be necessary.

In 12.1, a new configuration setting MIN_FREE_DISK_SPACE was added to "logs.conf" to stop the writing of logs when the hard disk containing the Logs folder gets low on disk space.


The need to clean up

If these files and folders are not correctly maintained, they could very easily fill the hard drive on the server, which may cause a number of significant problems. The scripts and methods described below can be used to clean up these files and folders at regular intervals, leaving only files from the past few days remaining.



Cleanup on Windows

The instructions provided here describe the process of setting up these cleanup scripts, but the actual instructions and screen settings you encounter may vary slightly depending on which version of Windows you are using.

To enable log cleanup, follow these steps:

1. Open the task scheduler, which can be done by typing “task” into my start menu search tool. This should show the following type of screen:


2. From the left side of the window, select the “Task Scheduler Library

3. Once selected, from the top menu, click “Action” option and select “Create Basic Task”, and give it an appropriate name, such as "Log File Cleanup", along with an optional description that you may find useful later, then click "next"


4. Determine how often you would like to run the cleanup script, we recommend running it every day using the "daily" option, then click "next".


5. You can now determine the time of day that the cleanup is performed. This can be midnight, or some other period of relative system inactivity. 


6. Once the time has been set, select “Start a program” from the action menu, to identify the program or script that you would like to run, then navigate to the directory that you are trying to cleanup, (Engine, License Server, etc…), which should be something like "C:\Program Files\LumenVox\Engine\" and select the file named "LumenVoxLogCleaner.bat".

7. In the field called “Start in” navigate to the path you are trying to clean, which should look similar to “C:\Program Files\LumenVox\Engine\”, where you selected the file.  The batch file will use a relative path from this location to perform cleanup of old log files and old/empty log folders.


8. Select “finish” and you are done!  The scheduled task will be run at the time and frequency that you selected.


Adjusting the cleanup script

If you need to change the way that the cleanup script works, you can open it in a text editor and change the settings. The script uses a command line utility called “forfiles”, as shown below - for more information on using this, type “forfiles /?” from the command prompt:

del /Q tmpDeleteFileList.txt
forfiles /P "Logs" /S /D -3 /C "cmd /c echo @relpath" >> tmpDeleteFileList.txt
for /F "tokens=*" %%A in (tmpDeleteFileList.txt) do call :process_delete_log_file %%A
del /Q tmpDeleteFileList.txt
goto :delete_log_folders


:process_delete_log_file
set tmpfile=%1
if /i "%tmpfile:~3,9%" neq "resources" (del /Q Logs\%tmpfile%)
goto :EOF


:delete_log_folders
forfiles /P "Logs" /S /D -1 /C "cmd /c if /i @isdir==true rd /Q @path"
goto :delete_resource_files


:delete_resource_files
forfiles /P "Logs\resources" /S /D -30 /C "cmd /c del /Q @path"

First the temporary file (tmpDeleteFileList.txt) is deleted in case it wasn't cleaned up last time the script ran. Then the "forfiles" utility is used to recursively search (“/S”) into the "Logs" directory (parameter following "/P") to find any file or folder older than 3 days (parameter following “/D”), and then run a command on the files that are found specified by the parameter following “/C”. The command ("cmd /c echo @relpath") prints the relative paths which are appended to a temporary file list (>> tmpDeleteFileList.txt). 

The "for" utility is used to iterate through the file list and delete any files that are not in the resources folder by calling:process_delete_log_file with each line in (tmpDeleteFileList.txt) as an argument. 

The temporary file (tmpDeleteFileList.txt) is deleted before jumping to the log folder deletion (goto :delete_log_folders). 

The "forfiles" utility is again used to recursively search (“/S”) into the "Logs" directory (parameter following "/P") to find any file or folder older than 1 days (parameter following “/D”), and then run a command on the files that are found specified by the parameter following “/C”. The command ("cmd /c if /i @isdir==true rd /Q @path") checks if the path specifies a folder and if so deletes the folder if it is empty. 

The resources files that are older than 30 days are then deleted (:delete_resource_files) using the "forfiles" utility.

Version 12.0
Note that in version 12.0, the following version of "LumenVoxLogCleaner.bat" is available.
forfiles /P "Logs" /S /D -3 /C "cmd /c del /Q @path"
forfiles /P "Logs" /S /D -1 /C "cmd /c rd /Q @path"

"forfiles" is used by the script to recursively search (“/S”) into the "Logs" directory (parameter following "/P") to find any file or folder older than the specified number of days (parameter following “/D”), and then run a command on the files that are found specified by the parameter following “/C”. The downside of this version is it deletes the resource logs every 3 days as well limiting the resource data available for display via the manager.

Changing the number of days that the cleanup script keeps is as easy as changing the parameter following the "/D" to something other than the default -3. The sign of the number should not be changed because this determines past or future files, and because we are looking for files in the past, this needs to stay negative. 

It is important to note that this cleanup script will not delete the folders that are not empty, so adjusting the first entry within the script file will leave files on disk for longer and restrict the deletion of the folders.

This cleanup script is included in each major LumenVox installation package for convenience, so locating it will depend on which folder you installed your packages to. 

Typical LumenVox installation paths in Windows are "C:\Program Files\LumenVox\" (64-bit Windows), or "C:\ Program Files (x86)\LumenVox\" (32-bit Windows), followed by the package name, which should be one of the following:

  • Engine
  • License Server
  • Tools
  • TTS (currently installed as 32-bit only)

There should be a copy of the cleanup script ("LumenVoxLogCleaner.bat") in each of these locations. Obviously if you install your packages to different locations, they will be located in those locations instead.

Please note that whenever files are deleted from a directory, the 'last-modified' date of that directory will change. This means that after deleting files from a given directory, the script will not be able to delete the (no empty) directory, due to the last-modified date,  until the requisite number of days have passed as determined by the parameter "/D" in the second line of theLumenVoxLogCleaner.bat. This “cascading” cleanup may therefore take a few days to completely remove all files and empty folders.



Cleanup on Linux

Logs file cleanup in Linux is achieved by adding two cron jobs - one to remove old files, the other to remove empty log folders.  LumenVox log files in Linux are located in the/var/log/lumenvox directory, so cleanup can be performed by using the following steps:

1. Log into your Linux terminal as a root user, then type "crontab -e" to open the cron table editor.
2. Add the next line to the bottom of the editor window, which will remove all log files older than 2 days except for the logs in the resources folder which are related to system monitoring. This will be performed at midnight every day.
0 0 * * * find /var/log/lumenvox -path/var/log/lumenvox/client/resources -prune -o -type f -mtime +2 -print0 | xargs-0 rm -f
3. Add the next line below the previous line, which will remove the resource logs after 30 days. This will be performed at 10 minutes past midnight every day.
10 0 * * * find /var/log/lumenvox/client/resources -type f -mtime +30 -delete
4. Add the next line below the previous line, which will remove empty folders older than 2 days. This will be performed at 20 minutes past midnight every day.
20 0 * * * find /var/log/lumenvox -type d -empty -ctime +2 -delete
5. Save and exit from the editor, after which the cleanup tasks will be enabled.


The first line will find any file within the specified path (/var/log/lumenvox) except for the resource files (-path /var/log/lumenvox/client/resources -prune -o) of type file (-type f) that has a modified date older than 2 days (-mtime +2) and print it with null separators (-print0). This is piped to (xargs -0) to protect the file names as individual arguments using '\0' as the delimiter and is then deleted (rm -f).
The second line will find any file (-type f) within the specified path (/var/log/lumenvox/client/resources)  that has a modified date older than 30 days (-mtime +30) and delete it (-delete)
The third line will find any directory (-type d) that is empty (-empty) that was created more than 2 days ago (-ctime +2) within the specified path (/var/log/lumenvox) and delete it (-delete)

Adjusting the cleanup script

You can adjust the amount of time that the script leaves the logs on the disk by increasing or decreasing the mtime of the first cron job. The times at which the cron jobs are performed can also be adjusted by altering the cron table entry. See the Wikipedia cron article for more details.