|
From: <jgr...@us...> - 2003-10-15 16:53:21
|
Update of /cvsroot/popfile/engine/POPFile
In directory sc8-pr-cvs1:/tmp/cvs-serv31121/POPFile
Modified Files:
Logger.pm
Log Message:
Make TICKD messages get sent every 6 hours; update test suite and use TICKD to delete log files
Index: Logger.pm
===================================================================
RCS file: /cvsroot/popfile/engine/POPFile/Logger.pm,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** Logger.pm 31 Jul 2003 16:32:21 -0000 1.22
--- Logger.pm 15 Oct 2003 16:53:14 -0000 1.23
***************
*** 42,46 ****
# Class new() function
#----------------------------------------------------------------------------
! sub new
{
my $proto = shift;
--- 42,46 ----
# Class new() function
#----------------------------------------------------------------------------
! sub new
{
my $proto = shift;
***************
*** 75,84 ****
# Start with debugging to file
$self->global_config_( 'debug', 1 );
# The default location for log files
$self->config_( 'logdir', './' );
! calculate_today__( $self );
return 1;
--- 75,89 ----
# Start with debugging to file
+
$self->global_config_( 'debug', 1 );
# The default location for log files
+
$self->config_( 'logdir', './' );
! $self->{last_tickd__} = time;
!
! $self->mq_register_( 'TICKD', $self );
! $self->calculate_today__();
return 1;
***************
*** 87,133 ****
# ---------------------------------------------------------------------------------------------
#
! # service
#
#
# ---------------------------------------------------------------------------------------------
! sub service
{
! my ( $self ) = @_;
! remove_debug_files( $self );
! return 1;
}
# ---------------------------------------------------------------------------------------------
#
! # remove_debug_files
! #
! # Removes popfile log files that are older than 3 days
#
# ---------------------------------------------------------------------------------------------
! sub remove_debug_files
{
my ( $self ) = @_;
! my $yesterday = defined($self->{today__})?$self->{today__}:0;
! calculate_today__( $self );
!
! if ( $self->{today__} > $yesterday ) {
! # Inform other modules that a day has passed
$self->mq_post_( 'TICKD', '', '' );
!
! my @debug_files = glob( $self->config_( 'logdir' ) . 'popfile*.log' );
!
! foreach my $debug_file (@debug_files) {
! # Extract the epoch information from the popfile log file name
! if ( $debug_file =~ /popfile([0-9]+)\.log/ ) {
! # If older than now - 3 days then delete
! unlink($debug_file) if ( $1 < (time - 3 * $seconds_per_day) );
! }
! }
}
}
--- 92,134 ----
# ---------------------------------------------------------------------------------------------
#
! # deliver
#
+ # Called by the message queue to deliver a message
+ #
+ # There is no return value from this method
#
# ---------------------------------------------------------------------------------------------
! sub deliver
{
! my ( $self, $type, $message, $parameter ) = @_;
! # If a day has passed then clean up log files
! if ( $type eq 'TICKD' ) {
! $self->remove_debug_files();
! }
}
# ---------------------------------------------------------------------------------------------
#
! # service
#
# ---------------------------------------------------------------------------------------------
! sub service
{
my ( $self ) = @_;
! $self->calculate_today__();
! # We send out a TICKD message every 6 hours so that other modules
! # can do clean up tasks that need to be done regularly but not
! # often
+ if ( time > ( $self->{last_tickd__} + 6 * 60 * 60 ) ) {
$self->mq_post_( 'TICKD', '', '' );
! $self->{last_tickd__} = time;
}
+
+ return 1;
}
***************
*** 148,151 ****
--- 149,174 ----
# ---------------------------------------------------------------------------------------------
#
+ # remove_debug_files
+ #
+ # Removes popfile log files that are older than 3 days
+ #
+ # ---------------------------------------------------------------------------------------------
+ sub remove_debug_files
+ {
+ my ( $self ) = @_;
+
+ my @debug_files = glob( $self->config_( 'logdir' ) . 'popfile*.log' );
+
+ foreach my $debug_file (@debug_files) {
+ # Extract the epoch information from the popfile log file name
+ if ( $debug_file =~ /popfile([0-9]+)\.log/ ) {
+ # If older than now - 3 days then delete
+ unlink($debug_file) if ( $1 < (time - 3 * $seconds_per_day) );
+ }
+ }
+ }
+
+ # ---------------------------------------------------------------------------------------------
+ #
# debug
#
***************
*** 177,184 ****
if ( $self->global_config_( 'debug' ) & 1 ) {
! open DEBUG, ">>$self->{debug_filename__}";
! binmode DEBUG;
! print DEBUG $msg;
! close DEBUG;
}
--- 200,210 ----
if ( $self->global_config_( 'debug' ) & 1 ) {
! if ( open DEBUG, ">>$self->{debug_filename__}" ) {
! binmode DEBUG;
! print DEBUG $msg;
! close DEBUG;
! } else {
! print "Can't write to log file $self->{debug_filename__}\n";
! }
}
|