2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

Archiving added to the main logfile

git-svn-id: https://svn.fhem.de/fhem/trunk@84 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2007-08-06 18:17:29 +00:00
parent ee3446ad39
commit bbeb12b59e
6 changed files with 81 additions and 65 deletions

View File

@ -321,7 +321,7 @@
documentation added.
- bugfix: more thorough serial line initialization
- ==DATE== (4.1)
- 2007-08-05 (4.1)
- doc: linux.html (private udev-rules, not 50-..., ATTRS)
- bugfix: setting devices with "-" in their name did not work
- doc: fhem.pl and commandref.html (notifyon -> notify, correction
@ -338,3 +338,6 @@
- bugfix: SCIVT solar controller (peterp, 1.7)
- bugfix: WS300 loglevel change (from 2 to 5 or device specific loglevel)
- feature: First steps for a Fritz!Box port. See the fritzbox.html
- ==DATE== (4.2)
- feature: added archivedir/archivecmd to the the main logfile

View File

@ -40,8 +40,8 @@ FileLog_Define($@)
$hash->{FH} = $fh;
$hash->{REGEXP} = $a[3];
$hash->{FILENAME} = $a[2];
$hash->{CURRENT} = $f;
$hash->{logfile} = $a[2];
$hash->{currentlogfile} = $f;
$hash->{STATE} = "active";
return undef;
@ -56,54 +56,6 @@ FileLog_Undef($$)
return undef;
}
# Make a directory and its parent directories if needed.
sub
HandleArchiving($)
{
my ($log) = @_;
my $ln = $log->{NAME};
return if(!$attr{$ln});
# If there is a command, call that
my $cmd = $attr{$ln}{archivecmd};
if($cmd) {
$cmd =~ s/%/$log->{CURRENT}/g;
Log 2, "Archive: calling $cmd";
system($cmd);
return;
}
my $nra = $attr{$ln}{nrarchive};
my $ard = $attr{$ln}{archivedir};
return if(!defined($nra));
# If nrarchive is set, then check the last files:
# Get a list of files:
my ($dir, $file);
if($log->{FILENAME} =~ m,^(.+)/([^/]+)$,) {
($dir, $file) = ($1, $2);
} else {
($dir, $file) = (".", $log->{FILENAME});
}
$file =~ s/%./.+/g;
return if(!opendir(DH, $dir));
my @files = sort grep {/^$file$/} readdir(DH);
closedir(DH);
my $max = int(@files)-$nra;
for(my $i = 0; $i < $max; $i++) {
if($ard) {
Log 2, "Moving $files[$i] to $ard";
rename("$dir/$files[$i]", "$ard/$files[$i]");
} else {
Log 2, "Deleting $files[$i]";
unlink("$dir/$files[$i]");
}
}
}
#####################################
sub
FileLog_Log($$)
@ -127,9 +79,9 @@ FileLog_Log($$)
my $fh = $log->{FH};
my @t = localtime;
my $cn = ResolveDateWildcards($log->{FILENAME}, @t);
my $cn = ResolveDateWildcards($log->{logfile}, @t);
if($cn ne $log->{CURRENT}) { # New logfile
if($cn ne $log->{currentlogfile}) { # New logfile
$fh->close();
HandleArchiving($log);
$fh = new IO::File ">>$cn";
@ -137,7 +89,7 @@ FileLog_Log($$)
Log(0, "Can't open $cn");
return;
}
$log->{CURRENT} = $cn;
$log->{currentlogfile} = $cn;
$log->{FH} = $fh;
}

View File

@ -127,3 +127,7 @@
- EM: added setTime, reset
- docs/fritzbox.html. Note: The fb_fhem_0.1.tar.gz won't be part of CVS
as it contains largee binaries (swapfile, perl mipsel executable, etc).
- Rudi Mon Aug 6 20:15:00 MEST 2007
- archiving added to the main logs.
NOTE: The FileLog filename (INT attribute) is now also called logfile.

View File

@ -2,7 +2,7 @@ BINDIR=/usr/local/bin
MODDIR=/usr/local/lib
VERS=4.0
DATE=2007-04-14
DATE=2007-08-05
DIR=fhem-$(VERS)
all:

View File

@ -47,6 +47,7 @@ sub CommandChain($$);
sub DoClose($);
sub GetLogLevel(@);
sub HandleTimeout();
sub HandleArchiving($);
sub IOWrite($@);
sub InternalTimer($$$);
sub Log($$);
@ -133,13 +134,14 @@ my %intAt; # Internal at timer hash.
my $intAtCnt=0;
my $reread_active = 0;
my $AttrList = "room comment";
my $cvsid = '$Id: fhem.pl,v 1.22 2007-08-05 09:48:26 rudolfkoenig Exp $';
my $cvsid = '$Id: fhem.pl,v 1.23 2007-08-06 18:17:28 rudolfkoenig Exp $';
$init_done = 0;
$modules{_internal_}{ORDER} = -1;
$modules{_internal_}{AttrList} = "configfile logfile lastinclude modpath " .
"pidfilename port statefile title userattr " .
"nrarchive archivedir archivecmd " .
"verbose:1,2,3,4,5 version";
@ -577,6 +579,10 @@ OpenLogfile($)
} else {
$defs{global}{currentlogfile} = $param;
$defs{global}{logfile} = $attr{global}{logfile};
HandleArchiving($defs{global});
open(LOG, ">>$currlogfile") || return("Can't open $currlogfile: $!");
# Redirect stdin/stderr
@ -1527,6 +1533,7 @@ ResolveDateWildcards($@)
return $f if(!$f);
return $f if($f !~ m/%/); # Be fast if there is no wildcard
my $S = sprintf("%02d", $t[0]); $f =~ s/%S/$S/g;
my $M = sprintf("%02d", $t[1]); $f =~ s/%M/$M/g;
my $H = sprintf("%02d", $t[2]); $f =~ s/%H/$H/g;
my $d = sprintf("%02d", $t[3]); $f =~ s/%d/$d/g;
@ -1643,9 +1650,59 @@ doGlobalDef($)
$defs{global}{TYPE} = "_internal_";
$defs{global}{STATE} = "<no definition>";
$defs{global}{DEF} = "<no definition>";
$defs{global}{NAME} = "global";
CommandAttr(undef, "global verbose 3");
CommandAttr(undef, "global configfile $arg");
CommandAttr(undef, "global logfile -");
CommandAttr(undef, "global version =VERS= from =DATE= ($cvsid)");
}
# Make a directory and its parent directories if needed.
sub
HandleArchiving($)
{
my ($log) = @_;
my $ln = $log->{NAME};
return if(!$attr{$ln});
# If there is a command, call that
my $cmd = $attr{$ln}{archivecmd};
if($cmd) {
$cmd =~ s/%/$log->{currentlogfile}/g;
Log 2, "Archive: calling $cmd";
system($cmd);
return;
}
my $nra = $attr{$ln}{nrarchive};
my $ard = $attr{$ln}{archivedir};
return if(!defined($nra));
# If nrarchive is set, then check the last files:
# Get a list of files:
my ($dir, $file);
if($log->{logfile} =~ m,^(.+)/([^/]+)$,) {
($dir, $file) = ($1, $2);
} else {
($dir, $file) = (".", $log->{logfile});
}
$file =~ s/%./.+/g;
return if(!opendir(DH, $dir));
my @files = sort grep {/^$file$/} readdir(DH);
closedir(DH);
my $max = int(@files)-$nra;
for(my $i = 0; $i < $max; $i++) {
if($ard) {
Log 2, "Moving $files[$i] to $ard";
rename("$dir/$files[$i]", "$ard/$files[$i]");
} else {
Log 2, "Deleting $files[$i]";
unlink("$dir/$files[$i]");
}
}
}

View File

@ -1,4 +1,4 @@
#Sun Aug 5 11:41:52 2007
#Mon Aug 6 19:30:33 2007
setstate FHZ fhtbuf: 1c
setstate FHZ 2006-02-12 14:03:39 fhtbuf 23
setstate FHZ 2006-03-26 08:47:36 init2 deadbeefdeadbe
@ -68,11 +68,11 @@ setstate wz 2006-03-26 08:52:31 unknown_85 4
setstate wz 2006-03-26 08:50:36 wed-from1 06:00
setstate wz 2006-03-26 08:50:36 wed-to1 23:00
setstate wz 2006-03-26 08:52:31 windowopen-temp 12.0 (Celsius)
setstate x 13.66 0.0 30 13.62 15.09 -0.2 2.8
setstate x 2007-08-05 11:41:50 Is 0.0
setstate x 2007-08-05 11:41:50 Temp 30
setstate x 2007-08-05 11:41:50 Vs 13.66
setstate x 2007-08-05 11:41:50 maxI 2.8
setstate x 2007-08-05 11:41:50 maxV 15.09
setstate x 2007-08-05 11:41:50 minI -0.2
setstate x 2007-08-05 11:41:50 minV 13.62
setstate x 13.66 0.0 30 13.62 15.09 -0.2 2.8
setstate x 2007-08-06 19:27:55 Is 0.0
setstate x 2007-08-06 19:27:55 Temp 30
setstate x 2007-08-06 19:27:55 Vs 13.66
setstate x 2007-08-06 19:27:55 maxI 2.8
setstate x 2007-08-06 19:27:55 maxV 15.09
setstate x 2007-08-06 19:27:55 minI -0.2
setstate x 2007-08-06 19:27:55 minV 13.62