use IO::Uncompress::UnXz qw($UnXzError);
use File::ReadBackwards;
use File::Copy;
+use Fcntl qw(:flock);
# Do not remove the following no critic, no security or object issues possible.
# We can use perls default behavior on return.
my $self = shift;
my $message = shift;
my $type = shift; $type = "" if !$type;
+ my $force_to_console = shift;
my $isWarning = $type eq 'WARNG';
my $attach = join @_; $message .= $attach if $attach;
my %log = $self -> property('%LOG');
$message =~ s/(\s+line\s)(\d+)\.*\s+/:$2\n/gm;
print $time . " " .$message;
}
- elsif(%log && $log{console}){
+ elsif(%log && ($force_to_console || $log{console})){
print $time . " " .$message ."\n"
}
if(%log && _isTrue($log{enabled}) && $message){
}
if($LOG_FILE){ # now available do it
open (my $fh, ">>", $LOG_FILE) or die $! . '->'. $LOG_FILE;
+ flock( $fh, LOCK_EX );
print $fh $time . " - " . $message ."\n";
+ flock( $fh, LOCK_UN );
close $fh;
if($LOG_TAIL_COUNT>0){
#2025-11-10 Mayor rewrite since v.3.3.6 Previous version was buffering and sorting unnecessary, slowing performance.
my $tmpFile = ensureDir("/tmp/".$log);
my $fh = File::ReadBackwards->new($LOG_FILE) or die $! . '->'. $LOG_FILE;
my $cut = $LOG_CURRENT_LINE_CNT - $LOG_TAIL_COUNT;
+
open (my $fhTemp, ">", $tmpFile) or die $! . '->'. $tmpFile;
for (1..$cut){
print $fhTemp $fh->readline()
open (my $fhLog, ">", $LOG_FILE) or die $!;
$fh = File::ReadBackwards->new($tmpFile) or die $! . '->'. $tmpFile;
+ flock( $fhLog, LOCK_EX );
for (1..$cut){
my $line = $fh->readline();
print $fhLog $line;
}
+ flock( $fhLog, LOCK_UN );
close $fhLog; $fh->close();
$LOG_CURRENT_LINE_CNT = $cut;
unlink $tmpFile