Add -N to start.py to disable to-file logging

This commit is contained in:
jesopo 2019-03-04 19:35:18 +00:00
parent cf262c6d8a
commit b43a5a7c74
2 changed files with 15 additions and 11 deletions

View file

@ -16,7 +16,7 @@ class BitBotFormatter(logging.Formatter):
return utils.iso8601_format(datetime_obj)
class Log(object):
def __init__(self, level: str, location: str):
def __init__(self, to_file: bool, level: str, location: str):
logging.addLevelName(LEVELS["trace"], "TRACE")
self.logger = logging.getLogger(__name__)
@ -35,16 +35,19 @@ class Log(object):
stdout_handler.setFormatter(formatter)
self.logger.addHandler(stdout_handler)
trace_handler = logging.handlers.TimedRotatingFileHandler(
os.path.join(location, "trace.log"), when="midnight", backupCount=5)
trace_handler.setLevel(LEVELS["trace"])
trace_handler.setFormatter(formatter)
self.logger.addHandler(trace_handler)
if to_file:
trace_path = os.path.join(location, "trace.log")
trace_handler = logging.handlers.TimedRotatingFileHandler(
trace_path, when="midnight", backupCount=5)
trace_handler.setLevel(LEVELS["trace"])
trace_handler.setFormatter(formatter)
self.logger.addHandler(trace_handler)
warn_handler = logging.FileHandler(os.path.join(location, "warn.log"))
warn_handler.setLevel(LEVELS["warn"])
warn_handler.setFormatter(formatter)
self.logger.addHandler(warn_handler)
warn_path = os.path.join(location, "warn.log")
warn_handler = logging.FileHandler(warn_path)
warn_handler.setLevel(LEVELS["warn"])
warn_handler.setFormatter(formatter)
self.logger.addHandler(warn_handler)
def trace(self, message: str, params: typing.List, **kwargs):
self._log(message, params, LEVELS["trace"], kwargs)

View file

@ -30,6 +30,7 @@ arg_parser.add_argument("--add-server", "-a",
arg_parser.add_argument("--verbose", "-V", action="store_true")
arg_parser.add_argument("--log-level", "-L")
arg_parser.add_argument("--no-logging", "-N", action="store_true")
arg_parser.add_argument("--module", "-m",
help="Execute an action against a specific module")
@ -46,7 +47,7 @@ log_level = args.log_level
if not log_level:
log_level = "debug" if args.verbose else "info"
log = Logging.Log(log_level, args.log_dir)
log = Logging.Log(not args.no_logging, log_level, args.log_dir)
database = Database.Database(log, args.database)
if args.add_server: