Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a log file in which continously data is written from various part of my code. Now want to limit the size of this log file to 20mb ie generate a new log file when it exceeds 10mb . For eg:

logfile_1 : size = 20 mb logfile_2 : size = 20 mb etc..

I used the -s switch to check the size of log file but how can i make it run through a loop such that assigns these names to log file automatically?

Replies are listed 'Best First'.
Re: Log File
by daxim (Curate) on Oct 15, 2012 at 07:58 UTC
    See How can I roll over my logfiles automatically at midnight? in Log::Log4perl::FAQ:
    When using Log::Dispatch::FileRotate, all you have to do is specify it in your Log::Log4perl configuration file and your logfiles will be rotated automatically.

    You can choose between rolling based on a maximum size ("roll if greater than 10 MB") or based on a date pattern ("roll everyday at midnight").

      Reading the faq i see that module Log::Dispatch::FileRotate can help me. But I am nt able to know how to use it? I am giving the code i am using presently::

      open(LOG,">file.txt") some code print LOG,"message"; some code print LOG,"message"; close(LOG;)

      How can i implement the above code through Log::Dispatch::FileRotate to change filename if size exceeds 10 mb?

        First, install the module from CPAN. Second, declare use of the module in your code (see use) . Third, call the module (as described in the module FAQ) at the desired point in your existing code.

        Additional info about modules can be found here. If you still have questions, consider checking other parts of perlintro as well.