From: Roman Bazalevsky Date: Mon, 23 May 2016 16:56:26 +0000 (+0300) Subject: Сделана настройка уровня отладочной информации в stdout - по умолчанию программа... X-Git-Url: https://git.rvb.name/weathermon.git/commitdiff_plain/3fd934fc66956e08777aaa10bd2ee27c1bc62758 Сделана настройка уровня отладочной информации в stdout - по умолчанию программа теперь пишет только в syslog --- diff --git a/weathermon b/weathermon index 8470f63..19688cb 100755 --- a/weathermon +++ b/weathermon @@ -55,9 +55,10 @@ def find_port(): def open_port(path): - global proc + global proc, debug - print "Opening path "+path + if debug>0: + print "Opening path "+path if path == "-": return sys.stdin @@ -106,12 +107,14 @@ def read_loop(ser,callback): try: line=read_port(ser) if line=="<>": - print "Reopening port..." - print line + if debug>0: + print "Reopening port..." + print line ser.close() if proc: try: - print "Terminating process..." + if debug>0: + print "Terminating process..." proc.terminate() sleep(5) finally: @@ -126,7 +129,8 @@ def read_loop(ser,callback): def print_log(str): global logging - print str + if debug>0: + print str if logging == "on": system("logger -t weathermon \""+str+"\"") @@ -151,11 +155,14 @@ def submit_narodmon(): queue=c.fetchall() - pprint(queue) + if debug>1: + pprint(queue) for (sensor,value) in queue: param[sensor] = value - pprint (param) + + if debug>1: + pprint (param) url = "http://narodmon.ru/post.php" @@ -208,11 +215,13 @@ def submit_owm(): queue=c.fetchall() - pprint(queue) + if debug>1: + pprint(queue) for (sensor,value) in queue: params[sensor]=value - pprint (params) + if debug>1: + pprint (params) try: @@ -360,7 +369,7 @@ def main(): def init(): - global dbhost,dbuser,dbpasswd,path,serialnum,logging; + global dbhost,dbuser,dbpasswd,path,serialnum,logging,debug; global timeout,baud,narmon,devid; global owmuser,owmpasswd,owm_temp,owm_pres,owm_humi,owm_lat,owm_lon,owm_station; global alarm_script; @@ -372,6 +381,10 @@ def init(): dbhost = cfg.get("mysql","host") dbuser = cfg.get("mysql","user") dbpasswd = cfg.get("mysql","passwd") + try: + debug = cfg.get("logging","debug") + except: + debug = 0 try: path = cfg.get("serial","port"); except: