HTTP-Daemon-Threaded

 view release on metacpan or  search on metacpan

lib/HTTP/Daemon/Threaded/Logger.pm  view on Meta::CPAN

@param $newpath	optional new logfile path

@return		none


=end classdoc

=cut
sub truncate {
	my ($self, $newpath) = @_;
#
#	close existing file
#	rename it with timestamp
#	open new file
#	reset size/time
#
	$newpath = $self->{Path}
		unless $newpath;

	my $fd = delete $self->{_fd};
	CORE::close($fd)
		if $fd;

	my @ts = split(/\s+/, scalar localtime());
	$ts[3]=~tr/:/_/;
	my $sfx = join('', '.', $ts[4], $ts[1], $ts[2], '_', $ts[3]);
	print STDERR "HTTP::Daemon::Threaded::Logger::truncate: Can't rename logfile: $!" and
	return undef
		unless rename $self->{Path}, $self->{Path} . $sfx;

	$self->{_logsize} = 0;
	$self->{_logtime} = time();

	print STDERR "HTTP::Daemon::Threaded::Logger::truncate: Can't open logfile: $!" and
	return undef
		unless open($fd, ">$newpath");

	my $old_fh = select($fd);
	$| = 1;
	select($old_fh);
	$self->{_fd} = $fd;

	$self->log("**************************************");
	$self->log('Logger: Logfile truncated.');
}
=pod

=begin classdoc

Update logfile lifetime. Called from WebClient.

@simplex
@param $lifetime	lifetime in hours.

@return		none


=end classdoc

=cut
sub updateLifetime {
	$_[0]->{Lifetime} = $_[1];
}
=pod

=begin classdoc

Update logfile maximum size. Called from WebClient.

@simplex
@param $maxsize	Maximum size in megabytes.

@return		none


=end classdoc

=cut
sub updateMaxSize {
	$_[0]->{MaxSize} = $_[1];
}
=pod

=begin classdoc

Update logfile name. Called from WebClient.
Truncates the existing logfile.

@simplex
@param $path	new logfile name

@return		none


=end classdoc

=cut
sub updatePath {
	my ($self, $newpath) = @_;

	$self->truncate($newpath);
	$self->{Path} = $newpath;
}

1;



( run in 0.628 second using v1.01-cache-2.11-cpan-524268b4103 )