Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Rotating output from the Perl debugger

by Booger (Pilgrim)
on Apr 20, 2005 at 16:34 UTC ( #449656=perlquestion: print w/replies, xml ) Need Help??
Booger has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I have a situation where I must debug a long running Perl process that is crashing once a week. I'm using the Perl debugger to accomplish this.

The problem is that the output from the Perl debugger is very large, size-wise, and since the Perl process is long running it is highly desirable that I rotate the log every couple of hours and compress old log files.

My usual methods of  cat /dev/null > debug.log and  echo > debug.log do not appear to be working properly; I assume this is because the file remains opened & locked by the Perl debugger? Is there another way to do this properly?

I suspect that this may not really be a Perl issue and more of a file-locking thing, however I'm curious to know if anyone has bothered to tackle this sort of thing before. Any suggestions or comments would be greatly appreciated!

Thanks in advance!


FWIW, the line I'm using to invoke the Perl debugger looks something like this:

 bash$ PERLDB_OPTS="NonStop LineInfo=debug.log frame=4 AutoTrace" perl -d --daemon

Resolved! Thank you everyone!

Replies are listed 'Best First'.
Re: Rotating output from the Perl debugger
by tall_man (Parson) on Apr 20, 2005 at 18:58 UTC
    I would suggest using Log::Dispatch::FileRotate for this. You can use LineInfo to direct the logging output to a pipe, running a script like this (not tested):
    use strict; use Log::Dispatch::FileRotate; my $file = Log::Dispatch::FileRotate->new( name => 'file1', min_level => 'info', filename => 'Somefile.log', mode => 'append' , TZ => '0:0:0:0:2:00:0', DatePattern => 'yyyy-dd-HH', ); while (<>) { $file->log( level => 'info', message => $_); }
      Thanks, tall_man!

      I actually did something similar to your suggestion (not having thought to look at the node to see if anyone had posted something interesting -- duh)

      I did this:

      #!/usr/bin/perl -w use warnings; use strict; use constant SIZEOF_100MB => 104857600; $| = 1; my $filename = 'debugfile'; while (<>) { open LOGFILE, ">>$filename" || die "Unable to open '$filename': $!"; print LOGFILE $_; close LOGFILE; my @stats = stat($filename); my $bsize = $stats[7]; if ( $bsize > SIZEOF_100MB ) { my @localtime = split / +|:/, localtime(); shift @localtime; pop @localtime; my $new = "${filename}_" . join '_', @localtime; rename $filename, $new; system("gzip $new"); } } 1;

      It's probably not as elegant as your solution (I wasted more lines) but it does work.

      Thanks again!

Re: Rotating output from the Perl debugger
by tcf03 (Deacon) on Apr 20, 2005 at 16:41 UTC
    Im not sure if this will work either, but have you tried  :> debug.log to zero it out?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://449656]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2018-02-21 06:02 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (275 votes). Check out past polls.