From 315d47860fbe7476710f8802faeacc46d998276e Mon Sep 17 00:00:00 2001 From: bentele <> Date: Mon, 26 Aug 2013 18:15:33 +0000 Subject: [PATCH] Log -> Log3 change git-svn-id: https://svn.fhem.de/fhem/trunk@3799 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/70_SML.pm | 79 +++++++++++++++++++++++---------------------- fhem/FHEM/70_STV.pm | 29 +++++++---------- 2 files changed, 52 insertions(+), 56 deletions(-) diff --git a/fhem/FHEM/70_SML.pm b/fhem/FHEM/70_SML.pm index 3c1fdf8f2..b50f4911a 100644 --- a/fhem/FHEM/70_SML.pm +++ b/fhem/FHEM/70_SML.pm @@ -46,31 +46,32 @@ my ($hash) = @_; $hash->{GetFn} = "energy_Get"; $hash->{StateFn} = "energy_State"; $hash->{SetFn} = "energy_Set"; - $hash->{AttrList} = "loglevel:0,1,2,3,4,5"; } sub energy_State($$$$) { my ($hash, $tim, $vt, $val) = @_; - Log 4, "time: $tim"; - Log 4, "name: $vt"; - Log 4, "value: $val"; + #Log 4, "time: $tim"; + #Log 4, "name: $vt"; + #Log 4, "value: $val"; $hash->{READINGS}{$vt}{VAL} = $val; $hash->{READINGS}{$vt}{TIME} = TimeNow(); - Log 4, "$hash->{NAME} VAL: $hash->{READINGS}{$vt}{VAL}"; + #Log 4, "$hash->{NAME} VAL: $hash->{READINGS}{$vt}{VAL}"; + Log3 $hash, 4, "time: $tim name: $vt value: $val"; return undef; } sub energy_Set($$$$) { my ($hash, $tim, $vt, $val) = @_; - Log 4, "time: $tim"; - Log 4, "name: $vt"; - Log 4, "value: $val"; + #Log 4, "time: $tim"; + #Log 4, "name: $vt"; + #Log 4, "value: $val"; $hash->{READINGS}{$vt}{VAL} = $val; $hash->{READINGS}{$vt}{TIME} = TimeNow(); - Log 4, "$hash->{NAME} VAL: $hash->{READINGS}{$vt}{VAL}"; + #Log 4, "$hash->{NAME} VAL: $hash->{READINGS}{$vt}{VAL}"; + Log3 $hash, 4, "time: $tim name: $vt value: $val"; if ( $vt eq "?"){ return "Unknown argument ?, choose one of DAYPOWER MONTHPOWER YEARPOWER TOTALPOWER"; } @@ -95,7 +96,8 @@ energy_Define($$) $hash->{Interval} = int(@args) >= 5 ? int($args[4]) : 300; $hash->{Timeout} = int(@args) >= 6 ? int($args[5]) : 4; - Log 4, "$hash->{NAME} will read from SML at $hash->{Host}:$hash->{Port} " ; + #Log 4, "$hash->{NAME} will read from SML at $hash->{Host}:$hash->{Port} " ; + Log3 $hash, 4, "$hash->{NAME} will read from SML at $hash->{Host}:$hash->{Port} " ; $hash->{Invalid} = -1; # default value for invalid readings $hash->{Rereads} = 2; # number of retries when reading curPwr of 0 $hash->{UseSVTime} = ''; # use the SV time as timestamp (else: TimeNow()) @@ -112,9 +114,9 @@ energy_Define($$) energy_Update($hash); - Log 3, "$hash->{NAME} will read from SML at $hash->{Host}:$hash->{Port} " . - ($hash->{Interval} ? "every $hash->{Interval} seconds" : "for every 'get $hash->{NAME} ' request"); - + #Log 3, "$hash->{NAME} will read from SML at $hash->{Host}:$hash->{Port} " . + # ($hash->{Interval} ? "every $hash->{Interval} seconds" : "for every 'get $hash->{NAME} ' request"); +Log3 $hash, 3, "$hash->{NAME} will read from SML at $hash->{Host}:$hash->{Port} " ; return undef; } @@ -127,8 +129,9 @@ energy_Update($) InternalTimer(gettimeofday() + $hash->{Interval}, "energy_Update", $hash, 0); } - Log 4, "$hash->{NAME} tries to contact SML at $hash->{Host}:$hash->{Port}"; - + #Log 4, "$hash->{NAME} tries to contact SML at $hash->{Host}:$hash->{Port}"; + Log3 $hash, 4, "$hash->{NAME} tries to contact SML at $hash->{Host}:$hash->{Port}"; + my $success = 0; my %readings = (); my $timenow = TimeNow(); @@ -150,8 +153,8 @@ energy_Update($) my $max = 0; my $log = ""; -Log 4, "$hash->{NAME} $url"; - +#Log 4, "$hash->{NAME} $url"; +Log3 $hash, 4, "$hash->{NAME} $url"; $socket = new IO::Socket::INET ( PeerAddr => $ip, PeerPort => $port, @@ -160,10 +163,10 @@ $socket = new IO::Socket::INET ( Timeout => $timeout ); -Log 4, "$hash->{NAME} socket new"; +Log3 $hash, 4, "$hash->{NAME} socket new"; if (defined ($socket) and $socket and $socket->connected()) { - Log 4, "$hash->{NAME} Connected ..."; + Log3 $hash, 4, "$hash->{NAME} Connected ..."; print $socket "GET $url HTTP/1.0\r\n\r\n"; $socket->autoflush(1); while ((read $socket, $buf, 1024) > 0) @@ -172,14 +175,14 @@ if (defined ($socket) and $socket and $socket->connected()) $message .= $buf; } $socket->close(); - Log 4, "$hash->{NAME} Socket closed"; + Log3 $hash, 4, "$hash->{NAME} Socket closed"; @array = split(/\n/,$message); foreach (@array){ if ( $_ =~ /(.*)<\/v>/ ){ - Log 5, "$hash->{NAME} got fresh values from $ip ($1)"; + Log3 $hash, 5, "$hash->{NAME} got fresh values from $ip ($1)"; if ( $1 eq "NaN" ){ - Log 5, "$hash->{NAME} NaN fehler ($1) summary: $summary"; + Log3 $hash, 5, "$hash->{NAME} NaN fehler ($1) summary: $summary"; }else{ $last = $1; $counts++ ; @@ -193,17 +196,17 @@ if (defined ($socket) and $socket and $socket->connected()) if ( $1 eq "true" ) { $success = 1; - Log 4, "$hash->{NAME} error from the $ip ($1)"; + Log3 $hash, 4, "$hash->{NAME} error from the $ip ($1)"; } } } }else{ - Log 3, "$hash->{NAME} Cannot open socket ..."; + Log3 $hash, 3, "$hash->{NAME} Cannot open socket ..."; $success = 1; return 0; } -Log 5, "reading done."; +Log3 $hash, 5, "reading done."; if ( $success == 0 and $summary > 0 and $counts > 0) { $avg = $summary/$counts; @@ -228,16 +231,16 @@ if ( $success == 0 and $summary > 0 and $counts > 0) }else{ my ($dateLast, $monthLast, $dayLast, $hourLast, $minLast, $secLast) = $hash->{READINGS}{DAYPOWER}{TIME} =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/; my ($powLast) = $hash->{READINGS}{DAYPOWER}{VAL} =~ /^(.*)$/; - Log 4, "$hash->{NAME} myhour: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; + Log3 $hash, 4, "$hash->{NAME} myhour: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; $hash->{READINGS}{DAYPOWER}{TIME} = $timenow; if ( $dayLast eq $day ){ # es ist der gleiche Tag $powLast += $newpower ; $hash->{READINGS}{DAYPOWER}{VAL} = $powLast; - Log 4, "$hash->{NAME} same day timenow: $timenow newpower $newpower powlast $powLast"; + Log3 $hash, 4, "$hash->{NAME} same day timenow: $timenow newpower $newpower powlast $powLast"; $log .= " day: $powLast"; }else{ # es ist eine Tag vergangen $hash->{READINGS}{DAYPOWER}{VAL} = $newpower; - Log 4, "$hash->{NAME} new day timenow: $timenow newpower $newpower powlast $powLast"; + Log3 $hash, 4, "$hash->{NAME} new day timenow: $timenow newpower $newpower powlast $powLast"; $log .= " day: $newpower"; } } @@ -247,16 +250,16 @@ if ( $success == 0 and $summary > 0 and $counts > 0) }else{ my ($dateLast, $monthLast, $dayLast, $hourLast, $minLast, $secLast) = $hash->{READINGS}{MONTHPOWER}{TIME} =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/; my ($powLast) = $hash->{READINGS}{MONTHPOWER}{VAL} =~ /^(.*)$/; - Log 4, "$hash->{NAME} myhour: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; + Log3 $hash, 4, "$hash->{NAME} myhour: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; $hash->{READINGS}{MONTHPOWER}{TIME} = $timenow; if ( $monthLast eq $month ){ # es ist der gleiche Monat $powLast += $newpower ; $hash->{READINGS}{MONTHPOWER}{VAL} = $powLast; - Log 4, "$hash->{NAME} Gleicher Monat timenow: $timenow newpower $newpower powlast $powLast"; + Log3 $hash, 4, "$hash->{NAME} Gleicher Monat timenow: $timenow newpower $newpower powlast $powLast"; $log .= " month: $powLast"; }else{ # es ist eine Monat vergangen $hash->{READINGS}{MONTHPOWER}{VAL} = $newpower; - Log 4, "$hash->{NAME} Neuer Monat timenow: $timenow newpower $newpower powlast $powLast"; + Log3 $hash, 4, "$hash->{NAME} Neuer Monat timenow: $timenow newpower $newpower powlast $powLast"; $log .= " month: $newpower"; } } @@ -266,16 +269,16 @@ if ( $success == 0 and $summary > 0 and $counts > 0) }else{ my ($dateLast, $monthLast, $dayLast, $hourLast, $minLast, $secLast) = $hash->{READINGS}{YEARPOWER}{TIME} =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/; my ($powLast) = $hash->{READINGS}{YEARPOWER}{VAL} =~ /^(.*)$/; - Log 4, "$hash->{NAME} myhour: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; + Log3 $hash, 4, "$hash->{NAME} myhour: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; $hash->{READINGS}{YEARPOWER}{TIME} = $timenow; if ( $yearhLast eq $year ){ # es ist das gleiche Jahr $powLast += $newpower ; $hash->{READINGS}{YEARPOWER}{VAL} = $powLast; - Log 4, "$hash->{NAME} Gleiches Jahr timenow: $timenow newpower $newpower powlast $powLast"; + Log3 $hash, 4, "$hash->{NAME} Gleiches Jahr timenow: $timenow newpower $newpower powlast $powLast"; $log .= " year: $powLast"; }else{ # es ist eine Jahr vergangen $hash->{READINGS}{YEARPOWER}{VAL} = $newpower; - Log 4, "$hash->{NAME} Neues Jahr timenow: $timenow newpower $newpower powlast $powLast"; + Log3 $hash, 4, "$hash->{NAME} Neues Jahr timenow: $timenow newpower $newpower powlast $powLast"; $log .= " year: $newpower"; } } @@ -286,16 +289,16 @@ if ( $success == 0 and $summary > 0 and $counts > 0) }else{ my ($dateLast, $monthLast, $dayLast, $hourLast, $minLast, $secLast) = $hash->{READINGS}{TOTALPOWER}{TIME} =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/; my ($powLast) = $hash->{READINGS}{TOTALPOWER}{VAL} =~ /^(.*)$/; - Log 4, "$hash->{NAME} total: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; + Log3 $hash, 4, "$hash->{NAME} total: $dateLast $monthLast $dayLast $hourLast $minLast $secLast $powLast"; $powLast += $newpower ; $hash->{READINGS}{TOTALPOWER}{VAL} = $powLast; $log .= " total: $powLast"; } push @{$hash->{CHANGED}}, $log; DoTrigger($hash->{NAME}, undef) if ($init_done); - Log 4, "$hash->{NAME} write log file: $log"; + Log3 $hash, 4, "$hash->{NAME} write log file: $log"; }else{ - Log 3, "$hash->{NAME} can't update - device send a error"; + Log3 $hash, 3, "$hash->{NAME} can't update - device send a error"; } return undef; @@ -322,7 +325,7 @@ energy_Update($hash) unless $hash->{Interval}; if ( $get eq "?"){ return "Unknown argument ?, choose one of minPower maxPower lastPower avgPower DAYPOWER MONTHPOWER YEARPOWER TOTALPOWER"; } - Log 3, "$args[0] $get => $val"; + Log3 $hash, 3, "$args[0] $get => $val"; return $val; } diff --git a/fhem/FHEM/70_STV.pm b/fhem/FHEM/70_STV.pm index 116f92f3b..3b73f1bbb 100644 --- a/fhem/FHEM/70_STV.pm +++ b/fhem/FHEM/70_STV.pm @@ -43,7 +43,7 @@ my ($hash) = @_; $hash->{StateFn} = "STV_SetState"; $hash->{SetFn} = "STV_Set"; $hash->{AttrFn} = "STV_Attr"; - $hash->{AttrList} = "MAC loglevel:0,1,2,3,4,5"; + $hash->{AttrList} = "MAC"; } sub @@ -133,8 +133,7 @@ if ( $hash->{Port} != 55000 && $hash->{Port} != 52235 ){ return "[STV] Port is not supported"; } - - Log 3, "[STV] defined with host: $hash->{Host} port: $hash->{Port} MAC: $hash->{MAC}"; + Log3 undef, 3, "[STV] defined with host: $hash->{Host} port: $hash->{Port} MAC: $hash->{MAC}"; $hash->{STATE} = 'Initialized'; return undef; } @@ -142,7 +141,7 @@ if ( $hash->{Port} != 55000 && $hash->{Port} != 52235 ){ sub connection($$) { my $tmp = shift ; - Log 4, "[STV] connection message: $tmp"; + Log3 undef, 4, "[STV] connection message: $tmp"; my $TV = shift; my $buffer = ""; my $tmp2 = ""; @@ -160,12 +159,11 @@ sub connection($$) $buffer .= $buff; } @tmp2 = split (/\n/,$buffer); - Log 3, "[STV] $TV response: $tmp2[0]"; - Log 4, "[STV] $TV buffer response: $buffer"; + $sock->close(); - Log 4, "[STV] $TV: socket closed"; + Log3 undef, 4, "[STV] $TV: socket closed"; }else{ - Log 4, "[STV] $TV: not able to close socket"; + Log3 undef, 4, "[STV] $TV: not able to close socket"; } } @@ -188,13 +186,13 @@ sub STV_55000($$$) #### MAC überprüfen wenn nicht gültig vom attribute übernehmen. if ($mymac !~ /^\w\w:\w\w:\w\w:\w\w|\w\w:\w\w:\w\w:\w\w$/) { - Log 3, "[STV] mymac: $mymac invalid format"; + Log3 $name, 3, "[STV] mymac: $mymac invalid format"; }else{ # command-line help if (!$tv|!$tvip|!$myip|!$mymac) { return "[STV] Error - Parameter missing:\nmodel, tvip, myip, mymac."; } - Log GetLogLevel($name,5), "[STV] opening socket with tvip: $tvip, cmd: $cmd"; + Log3 $name, 5, "[STV] opening socket with tvip: $tvip, cmd: $cmd"; my $sock = new IO::Socket::INET ( PeerAddr => $tvip, PeerPort => $port, @@ -202,10 +200,6 @@ sub STV_55000($$$) Timout => 5 ); if (defined ($sock)){ - # Log GetLogLevel($name,3), "[STV] Could not create socket. Aborting." unless $sock; - # die "Could not create socket: $!\n" unless $sock; - # return "Could not create socket: $!\n" unless $sock; - # Log GetLogLevel($name,3), "[STV] Could not create socket. Aborting."; my $messagepart1 = chr(0x64) . chr(0x00) . chr(length(encode_base64($myip, ""))) . chr(0x00) . encode_base64($myip, "") . chr(length(encode_base64($mymac, ""))) . chr(0x00) . encode_base64($mymac, "") . chr(length(encode_base64($remotename, ""))) . chr(0x00) . encode_base64($remotename, ""); my $part1 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart1)) . chr(0x00) . $messagepart1; print $sock $part1; @@ -225,7 +219,7 @@ sub STV_55000($$$) else { foreach my $argnum (0 .. $#ARGV) { # Send remote key(s) - Log GetLogLevel($name,4), "[STV] sending ".uc($ARGV[$argnum]); + #Log4 $name, 4, "[STV] sending ".uc($ARGV[$argnum]); my $key = "KEY_" . uc($ARGV[$argnum]); my $messagepart3 = chr(0x00) . chr(0x00) . chr(0x00) . chr(length(encode_base64($key, ""))) . chr(0x00) . encode_base64($key, ""); my $part3 = chr(0x00) . chr(length($tvappstring)) . chr(0x00) . $tvappstring . chr(length($messagepart3)) . chr(0x00) . $messagepart3; @@ -237,7 +231,7 @@ sub STV_55000($$$) close($sock); }else{ - Log GetLogLevel($name,3), "[STV] Could not create socket. Aborting." unless $sock; + #Log5 $name, 3, "[STV] Could not create socket. Aborting." unless $sock; } } } @@ -251,7 +245,6 @@ sub STV_52235($@$@) my $TV = $hash->{Host}; my $count = @a; my $arg = lc($a[2]); # mute volume -#Log 1, "name: $name host: $TV count: $count 0 $a[0] 1 $a[1] 2 $a[2]"; my $cont1 = ucfirst($arg); # Mute my $cont2 = ""; my $cont3 = ""; @@ -291,7 +284,7 @@ if ( $arg eq "volume") if ( $cont2 > 0 and $cont2 < 100 ){ $kind = 1; }else { - Log 3, "[STV] $name Volume: not correct"; + Log3 $name, 3, "[STV] $name Volume: not correct"; $kind = 0; } }