diff --git a/logger.pm b/logger.pm index 9e4e211..e13af3b 100644 --- a/logger.pm +++ b/logger.pm @@ -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 {