add bot.conf options so we can disable given log files

This commit is contained in:
jesopo 2020-04-10 22:53:19 +01:00
parent 00730a5384
commit 61f050e329
3 changed files with 30 additions and 19 deletions

View file

@ -62,7 +62,10 @@ log_level = args.log_level
if not log_level:
log_level = "debug" if args.verbose else "warn"
log = Logging.Log(not args.no_logging, log_level, LOG_DIR)
log_level_files = config.get("log-levels", "TRACE,INFO,WARN"
).split(",")
log = Logging.Log(not args.no_logging, log_level, LOG_DIR, log_level_files)
log.info("Starting BitBot %s (Python v%s, db %s)",
[IRCBot.VERSION, platform.python_version(), DATABASE])

View file

@ -11,6 +11,8 @@
#lock-file = {DATA}/bot.lock
#sock-file = {DATA}/bot.sock
#log-levels = TRACE,INFO,WARN
# database - currently only supports sqlite3
#database = sqlite3:{DATA}/bot.db

View file

@ -27,7 +27,10 @@ class HookedHandler(logging.StreamHandler):
class Log(object):
_hooks: typing.List[typing.Callable[[int, str], None]]
def __init__(self, to_file: bool, level: str, location: str):
def __init__(self, to_file: bool,
level: str,
location: str,
file_levels: typing.List[str]):
self._hooks = []
logging.addLevelName(LEVELS["trace"], "TRACE")
@ -52,6 +55,7 @@ class Log(object):
self.logger.addHandler(hook_handler)
if to_file:
if "TRACE" in file_levels:
trace_path = os.path.join(location, "trace.log")
trace_handler = logging.handlers.TimedRotatingFileHandler(
trace_path, when="midnight", backupCount=5)
@ -59,6 +63,7 @@ class Log(object):
trace_handler.setFormatter(formatter)
self.logger.addHandler(trace_handler)
if "INFO" in file_levels:
info_path = os.path.join(location, "info.log")
info_handler = logging.handlers.TimedRotatingFileHandler(
info_path, when="midnight", backupCount=1)
@ -66,6 +71,7 @@ class Log(object):
info_handler.setFormatter(formatter)
self.logger.addHandler(info_handler)
if "WARN" in file_levels:
warn_path = os.path.join(location, "warn.log")
warn_handler = logging.FileHandler(warn_path)
warn_handler.setLevel(LEVELS["warn"])