Armadito-Agent

 view release on metacpan or  search on metacpan

lib/Armadito/Agent/Logger/File.pm  view on Meta::CPAN

				return;
			}
		}
	}

	if ( !$handle && !open $handle, '>>', $self->{logfile} ) {
		warn "can't open $self->{logfile}: $ERRNO";
		return;
	}

	my $locked;
	my $retryTill = time + 60;

	while ( $retryTill > time && !$locked ) {
		## no critic (ProhibitBitwise)
		# get an exclusive lock on log file
		$locked = 1 if flock( $handle, LOCK_EX | LOCK_NB );
	}

	if ( !$locked ) {
		die "can't get an exclusive lock on $self->{logfile}: $ERRNO";
	}

	print {$handle} "[" . localtime() . "]" . "[$level]" . " $message\n";

	# closing handle release the lock automatically
	close $handle;

}



( run in 0.485 second using v1.01-cache-2.11-cpan-49f99fa48dc )