Logger: Update output file after date change

This commit is contained in:
mrkubax10 2023-09-18 10:07:15 +02:00
parent d89006fb46
commit 94696bc4f1

View File

@ -156,7 +156,25 @@ sub prepareLogFile {
my $aServerName = $_[1];
my $aChannelName = $_[2];
if(!exists($aLogFiles->{$aChannelName})) {
if(exists($aLogFiles->{$aChannelName})) {
my $filename = localtime->dmy("-").".txt";
if($filename ne $aLogFiles->{$aChannelName}{"filename"}) {
close($aLogFiles->{$aChannelName}{"file"});
my $outputFileFolder = $configuration::logFolder."/".$aServerName."/".$aChannelName;
my $outputFilePath = $outputFileFolder."/".$filename;
open(my $file, ">>", $outputFilePath);
if($file) {
printf("[info] Outputting channel '%s' at '%s' to '%s'\n", $aChannelName, $aServerName, $outputFilePath);
$aLogFiles->{$aChannelName}{"file"} = $file;
$aLogFiles->{$aChannelName}{"filename"} = $filename;
}
else {
print("[error] Failed to open '$outputFilePath' for writing\n");
return 0;
}
}
}
else {
my $outputFileFolder = $configuration::logFolder."/".$aServerName."/".$aChannelName;
if(!(-e $outputFileFolder)) {
File::Path::make_path($outputFileFolder);
@ -166,6 +184,7 @@ sub prepareLogFile {
if($file) {
printf("[info] Outputting channel '%s' at '%s' to '%s'\n", $aChannelName, $aServerName, $outputFilePath);
$aLogFiles->{$aChannelName}{"file"} = $file;
$aLogFiles->{$aChannelName}{"filename"} = localtime->dmy("-").".txt";
$aLogFiles->{$aChannelName}{"names"} = [];
}
else {