From 2c46fbf16645d6e5fb6b577a176781a77a50644c Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 7 Jan 2012 08:19:15 +0000 Subject: [PATCH] get needs to check for filename change too git-svn-id: https://svn.fhem.de/fhem/trunk@1175 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/92_FileLog.pm | 46 ++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/fhem/FHEM/92_FileLog.pm b/fhem/FHEM/92_FileLog.pm index 54ace9772..61d91991d 100755 --- a/fhem/FHEM/92_FileLog.pm +++ b/fhem/FHEM/92_FileLog.pm @@ -62,6 +62,29 @@ FileLog_Undef($$) return undef; } +sub +FileLog_Switch($) +{ + my ($log) = @_; + + my $fh = $log->{FH}; + my @t = localtime; + my $cn = ResolveDateWildcards($log->{logfile}, @t); + + if($cn ne $log->{currentlogfile}) { # New logfile + $fh->close(); + HandleArchiving($log); + $fh = new IO::File ">>$cn"; + if(!defined($fh)) { + Log(0, "Can't open $cn"); + return; + } + $log->{currentlogfile} = $cn; + $log->{FH} = $fh; + } + +} + ##################################### sub FileLog_Log($$) @@ -81,24 +104,11 @@ FileLog_Log($$) if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/) { my $t = TimeNow(); $t = $dev->{CHANGETIME}[$i] if(defined($dev->{CHANGETIME}[$i])); - $t =~ s/ /_/o; # Makes it easier to parse with gnuplot + $t =~ s/ /_/; # Makes it easier to parse with gnuplot + + FileLog_Switch($log); my $fh = $log->{FH}; - my @t = localtime; - my $cn = ResolveDateWildcards($log->{logfile}, @t); - - if($cn ne $log->{currentlogfile}) { # New logfile - $fh->close(); - HandleArchiving($log); - $fh = new IO::File ">>$cn"; - if(!defined($fh)) { - Log(0, "Can't open $cn"); - return; - } - $log->{currentlogfile} = $cn; - $log->{FH} = $fh; - } - print $fh "$t $n $s\n"; $fh->flush; $fh->sync if !($^O eq 'MSWin32'); #not implemented in Windows @@ -179,12 +189,14 @@ FileLog_Get($@) $internal = 1; } + FileLog_Switch($hash); + if($inf eq "-") { $inf = $hash->{currentlogfile}; } else { my $linf = "$1/$inf" if($hash->{currentlogfile} =~ m,^(.*)/[^/]*$,o); if(!-f $linf) { - $linf = AttrValue($hash->{NAME},"archivedir",".") ."/". $inf; + $linf = AttrVal($hash->{NAME},"archivedir",".") ."/". $inf; return "Error: cannot access $linf" if(!-f $linf); } $inf = $linf;