2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 12:58:13 +00:00

get needs to check for filename change too

git-svn-id: https://svn.fhem.de/fhem/trunk@1175 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-01-07 08:19:15 +00:00
parent c43b5f202f
commit 2c46fbf166

View File

@ -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;