Skip to end of metadata
Go to start of metadata

Delete Log Files with the Logeraser Utility

To manage the size of the files generated from activity logs and other system activity, it can be useful to delete past log files. For example, it's often useful to simply delete any log files after a set amount of time has passed, such as every month or quarter. This is done automatically with a utility called Logeraser, which is installed in the standard set of Agiloft files and located in the <ROOT>/bin directory.

The logeraser utility works by deleting, keeping, or compressing files based on the age of files in a given file set and the amount of free disk space you want. The utility automatically adds files to different file sets based on a default file mask, which is a method for finding and grouping files using a regular expression, or regex. You can define your own file mask, as well as how files are processed in each file set by defining parameters for file age and disk space.

Example

Consider a file set A that contains all files with an extension of .log in directory X. In this set, you can choose to delete all files older than 180 days, keep files younger than 30 days, and compress files older than 5 days. You can also choose to delete files older than 30 days but younger than 180 days until you have at least 50 percent of free disk space.

You may also have another file set B that contains all files with an extension of .hprof in directory Y . In this set, you can define the file age parameters differently, such as choosing to delete all files older than 90 days, keep files younger than 10 days, and compress files older than 1 day. However, when you delete files older than 10 days but younger than 90 days, you must use the same disk space parameter for all file sets.

You do not need to manually run the utility to delete files, except to change the configuration settings. The utility automatically deletes any files that meet the configuration parameters. By default, log files in the default file sets are deleted after 30 days.

Prerequisite

To configure Logeraser and change its default settings, you must have access to the file directory on the server.

Processing Algorithm

Each file set contains independent parameters that determine which files Logeraser deletes, keeps, and compresses:

  • black: Files older than this age are deleted unconditionally.
  • white: Files younger than this age are kept unconditionally.
  • zip: Files older than this age are compressed, or zipped.

Gray Files

Gray files are files older than the white parameter but younger than the black parameter. Logeraser deletes gray files in order from oldest to newest until a defined percentage of disk space is free. Two parameters define the the amount of disk space that affect gray files:

  • startthreshold: Defines the amount of free disk space that must be unavailable before Logeraser begins deleting gray files. If you have more free disk space than is defined by this parameter, no gray files are deleted.
  • finishthreshold: Defines the amount of free disk space that must be available before Logeraser stops deleting gray files. When the free disk space reaches the amount defined by this parameter, the remaining gray files are kept. 

Delete Log Files

To configure Logeraser, go to the <ROOT>/bin directory containing the utility and open it. The utility uses commands and parameters that you need to enter in the command line to change the utility's configuration. For a full list of commands and parameters, see Logeraser Reference at the end of this article.

The default settings for Logeraser are typically sufficient for most purposes. If you want to change the configuration, follow each section below in order.

Print the Current Configuration

Use the -i command to print the current configuration. This shows you the directories, file masks, names, and parameters for all file sets. 

server32b:/shar/srv/AGILOFT_HOME # ./bin/logeraser -i

Main parameters:
        Installation root : /shar/srv/AGILOFT_HOME
                 Log file : /shar/srv/AGILOFT_HOME/logs/logeraser.log
          Start threshold : 50
         Finish threshold : 55

File sets:
                          name : jbosslogs
                     Directory : /shar/srv/AGILOFT_HOME/jboss/server/sw/log
                     File mask : .+\.log.*
               Process subdirs : false
             Delete older than : 30 days (Sat Feb 13 04:11:38 GMT+00:00 2010)
             Keep younger than : 7 days (Mon Mar 08 04:11:38 GMT+00:00 2010)
                Zip older than : 2 days (Sat Mar 13 04:11:38 GMT+00:00 2010)

                          name : hprofs
                     Directory : /shar/srv/AGILOFT_HOME/jboss/bin
                     File mask : .+\.hprof
               Process subdirs : false
             Delete older than : 30 days (Sat Feb 13 04:11:38 GMT+00:00 2010)
             Keep younger than : not set
                Zip older than : not set

                          name : temps
                     Directory : /shar/srv/AGILOFT_HOME/tmp
                     File mask : .+
               Process subdirs : true
             Delete older than : 30 days (Sat Feb 13 04:11:38 GMT+00:00 2010)
             Keep younger than : not set
                Zip older than : not set

File Sets

The configuration contains three file sets for processing:

  • jbosslogs: Consists of all files in the /shar/srv/AGILOFT_HOME/jboss/server/sw/log directory with .log in their name.
  • hprofs: Consists of files with extension .hprof in the /shar/srv/AGILOFT_HOME/jboss/bin directory.
  • temps: Consists of all files in the /shar/srv/AGILOFT_HOME/tmp directory.

These three file sets are standard and created automatically. In the example above, the root directory for Agiloft files is /shar/srv/AGILOFT_HOME . Your configuration may differ depending on your installation directory.

Edit Parameters

Use the -F command to reference a file set to edit its parameters. For example, to change the black parameter from 30 days to 15 days for the jbosslogs file set, as well as to display the resulting configuration, execute the following command:

server32b:/shar/srv/AGILOFT_HOME # ./bin/logeraser -F jbosslogs -B 15 -i

The utility makes the specified change to the referenced file set and parameter, and the resulting configuration is printed because the -i command is used:

server32b:/shar/srv/AGILOFT_HOME # ./bin/logeraser -F jbosslogs -B 15 -i

Main parameters:
        Installation root : /shar/srv/AGILOFT_HOME
                 Log file : /shar/srv/AGILOFT_HOME/logs/logeraser.log
          Start threshold : 50
         Finish threshold : 55

File sets:
                          name : jbosslogs
                     Directory : /shar/srv/AGILOFT_HOME/jboss/server/sw/log
                     File mask : .+\.log.*
               Process subdirs : false
             Delete older than : 15 days (Sun Feb 28 05:08:04 GMT+00:00 2010)
             Keep younger than : 7 days (Mon Mar 08 05:08:04 GMT+00:00 2010)
                Zip older than : 2 days (Sat Mar 13 05:08:04 GMT+00:00 2010)

                          name : hprofs
                     Directory : /shar/srv/AGILOFT_HOME/jboss/bin
                     File mask : .+\.hprof
               Process subdirs : false
             Delete older than : 30 days (Sat Feb 13 05:08:04 GMT+00:00 2010)
             Keep younger than : not set
                Zip older than : not set

                          name : temps
                     Directory : /shar/srv/AGILOFT_HOME/tmp
                     File mask : .+
               Process subdirs : true
             Delete older than : 30 days (Sat Feb 13 05:08:04 GMT+00:00 2010)
             Keep younger than : not set
                Zip older than : not set

For each parameter you want to edit for a given file set, follow a similar process.

Test the File Processing

Use the -n command to perform a "dry run" on the files and see which files are processed by the utility:

server32b:/shar/srv/AGILOFT_HOME # ./bin/logeraser -F jbosslogs -n -r -v -c

If the files are processed as you expect, remove the -n command and run the utility to immediately remove the desired log files. In the future, log files meeting the configuration settings are automatically processed by the utility. You do not need to manually run Logeraser.

The log files from running Logeraser itself, such as what was processed and when, are stored in the <ROOT>/logs directory and named logeraser.log.

Logeraser Reference

The following list is a reference of all Logeraser commands and parameters. To see this list in Logeraser, run the utility without entering any options:

server32b:/shar/srv/AGILOFT_HOME # ./bin/logeraser
usage: Usage

 -B, black              Black file age of the configured file set
 -D, directory          Directory of the configured file set
 -E, before             Insert new file set before named
 -F, fileset            File set name for configuration
 -M, mask               File name mask for the configured file set
 -R, remove             Remove file set from configuration
 -S, subdirs            Process sub-directories for the configured file set
 -T, finishthreshold    Finish threshold value
 -W, white              White file age of the configured file set
 -Z, zip                Zip file age of the configured file set
 -c, console            Output to console
 -i, info               Print current configuration
 -n, dryrun             Dry run (no files removed)
 -r, run                Remove old log files
 -t, startthreshold     Start threshold value
 -v, verbose            Verbose output