The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::SolarWinds::FileRotationBase - base file rotation framework

SYNOPSIS

use base qw(Net::SolarWinds::FileRotationBase);

DESCRIPTION

This modle is intended to be used as a base module for modules that require an auto file rotation framework. Auto file rotation is handled by file size.

OO Methods

  • Object constructor

    The object constructor for this class has a collection of optional arguments. Arguments are passed to the constructor in key value pairs.

    Constructor useage example:

    my $fr=new Net::SolarWinds::FileRotationBase(folder=>'/var/logs/myapp',basefilename=>'someapp');

    Argument list is as follows (default values shown):

    # Fully quallified system path to the log file
    filename=>'/path/to/some/file.log'
    
    # sets the folder files will be created and rotated under
    folder=>'.',  
    
    # sets the basefilename
    basefilename => 'DefaultFile',
    
    # used to concat the folder and filenames togeather
    pathconncat  => '/',
    
    # sets thefile extention to be used
    ext => 'log',
    
    # sets the number of files to keep in rotation
    maxfilecount => 3,
    
    # sets the max file size ( 8mb )
    maxsize      => 1024 * 1024 * 8,
    
    # sets the autoflush state ( handy for real time info in the file )
    autoflush    => 1,
    
    # sets the file auto rotation flag
    autorotate   => 1,
    
    # glob ref will be overwritten with the current fh
    mirror=>undef|\*STDERR
  • $fr->set_mirror(\*STDERR);

    Sets a file handle to be mirroed to:

  • my $filename=$fr->generate_filename;

    Retuns the filename of the active file.

  • my $fh=$fr->get_fh;

    Returns the active filehandle.

  • $fr->rotate_files

    Forces log files to be rotated now!

  • $fr->close_fh;

    Closes the current active file handle.

  • $fr->write_to_file("Something to write to my file\n");

    Writes the list of arguments to the target file.

AUTHOR

Michael Shipper