Merge pull request #1028 from GNS3/filter_logs

Filter /settings from log
This commit is contained in:
Jeremy Grossmann 2017-05-12 17:31:42 +08:00 committed by GitHub
commit 9baaf5685d

View File

@ -98,6 +98,16 @@ class WinStreamHandler(logging.StreamHandler):
self.handleError(record)
class LogFilter:
"""
This filter some noise from the logs
"""
def filter(record):
if record.name == "aiohttp.access" and "/settings" in record.msg and "200" in record.msg:
return 0
return 1
def init_logger(level, logfile=None, quiet=False):
if logfile and len(logfile) > 0:
stream_handler = logging.FileHandler(logfile)
@ -111,5 +121,7 @@ def init_logger(level, logfile=None, quiet=False):
if quiet:
stream_handler.addFilter(logging.Filter(name="user_facing"))
logging.getLogger('user_facing').propagate = False
if level > logging.DEBUG:
stream_handler.addFilter(LogFilter)
logging.basicConfig(level=level, handlers=[stream_handler])
return logging.getLogger('user_facing')