Module: LogRotate
- Defined in:
- lib/logrotate/version.rb,
lib/logrotate/impl.rb,
lib/logrotate/logrotate.rb,
lib/logrotate/rotateinfo.rb
Overview
This module provides a few methods for log rotation.
Defined Under Namespace
Modules: Impl, VERSION Classes: RotateInfoDateExtension, RotateInfoIntegerExtension
Class Method Summary collapse
-
.rotate_file(file, options) ⇒ Object
Description: This method rotates the given file or directory.
-
.rotate_files(files, options) ⇒ Object
Description: This method rotates the given files and/or directories.
Class Method Details
.rotate_file(file, options) ⇒ Object
Description:
This method rotates the given file or directory.
There are 2 types of extensions that can be used: the default extension which is an integer value (“.1”, “.2”, ..), and a date/time extension (“.2008-08-01”, ..). If a date/time extension is chosen, the caller can specify a date/time format for this extension.
If this method fails, an exception will be thrown. If this method succeeds, the method will return normally, and an instance will be returned with information about the rotated files.
Note: If a directory is passed in to be rotated, the gzip option does not apply / can not be used. In this case, please tar the directory and then call rotate_file on the tar’ed file.
Parameters:
- file
-
The file to be rotated.
- options = {}
-
A list of optional arguments.
The optional arguments are listed below:
count-
The number of rotated files to be kept.
directory-
The directory to store the newly rotated file. If this option is unspecified, the original file’s directory will be used.
date_time_ext-
Whether the extension on the rotated files should be a date. Possible values are:
true,false. date_time_format-
For use with
date_time_ext. This specifies the format of the date / time extension. date_time-
For use with
date_time_ext. TheDateTimethat will be used to construct the extension of the newly rotated file.If this option is not specified, the current date and time will be used.
pre_rotate-
A
Procto be executed before the rotation is started. post_rotate-
A
Procto be executed after the rotation is finished, and before the newly rotated file is zipped. gzip-
Whether the newly rotated file should be gzipped. Possible values are:
true,false. Note: This option can not be used on directories.
To see the default values of these options, see the DEFAULT_ constants in LogRotate::Impl.
Returns:
A RotateInfoDateExtension or RotateInfoIntegerExtension instance depending whether the option date_time_ext was specified. This instance contains information about the rotated files.
86 87 88 |
# File 'lib/logrotate/logrotate.rb', line 86 def self.rotate_file(file, ) return Impl.send(:rotate_single_file, file, ) end |
.rotate_files(files, options) ⇒ Object
Description:
This method rotates the given files and/or directories.
Parameters:
- file(s)
-
The files to be rotated.
- options = {}
-
A list of optional arguments.
See rotate_file for details.
Returns:
A list of RotateInfoDateExtension or RotateInfoIntegerExtension instances depending whether the option date_time_ext was specified.
29 30 31 32 33 |
# File 'lib/logrotate/logrotate.rb', line 29 def self.rotate_files(files, ) return files.map do |file| Impl.send(:rotate_single_file, file, ) end end |