From bddb764bc1fa0181872636a7c0b39ceab0e34add Mon Sep 17 00:00:00 2001 From: Joseph Pan Date: Sun, 24 Dec 2017 16:36:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20--verbose=20=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E9=80=89=E9=A1=B9=EF=BC=8C=E6=94=AF=E6=8C=81=E5=9C=A8?= =?UTF-8?q?=E5=B1=8F=E5=B9=95=E4=B8=AD=E7=9B=B4=E6=8E=A5=E6=89=93=E5=8D=B0?= =?UTF-8?q?=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dingdang.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/dingdang.py b/dingdang.py index d47aef5..602902e 100755 --- a/dingdang.py +++ b/dingdang.py @@ -30,6 +30,8 @@ help='Run diagnose and exit') parser.add_argument('--debug', action='store_true', help='Show debug messages') parser.add_argument('--info', action='store_true', help='Show info messages') +parser.add_argument('--verbose', action='store_true', + help='Directly print logs rather than writing to log file') args = parser.parse_args() if args.local: @@ -195,14 +197,21 @@ def run(self): ''') - logging.basicConfig( - filename=os.path.join( - dingdangpath.TEMP_PATH, "dingdang.log" - ), - filemode="w", - format='%(asctime)s %(filename)s[line:%(lineno)d] \ + if args.verbose: + logging.basicConfig( + format='%(asctime)s %(filename)s[line:%(lineno)d] \ %(levelname)s %(message)s', - level=logging.INFO) + level=logging.INFO) + else: + logging.basicConfig( + filename=os.path.join( + dingdangpath.TEMP_PATH, "dingdang.log" + ), + filemode="w", + format='%(asctime)s %(filename)s[line:%(lineno)d] \ + %(levelname)s %(message)s', + level=logging.INFO) + logger = logging.getLogger() logger.getChild("client.stt").setLevel(logging.INFO)