add bot.conf options so we can disable given log files
This commit is contained in:
parent
9dfbe3723c
commit
32e2156e1e
3 changed files with 30 additions and 19 deletions
5
bitbotd
5
bitbotd
|
@ -62,7 +62,10 @@ log_level = args.log_level
|
||||||
if not log_level:
|
if not log_level:
|
||||||
log_level = "debug" if args.verbose else "warn"
|
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)",
|
log.info("Starting BitBot %s (Python v%s, db %s)",
|
||||||
[IRCBot.VERSION, platform.python_version(), DATABASE])
|
[IRCBot.VERSION, platform.python_version(), DATABASE])
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#lock-file = {DATA}/bot.lock
|
#lock-file = {DATA}/bot.lock
|
||||||
#sock-file = {DATA}/bot.sock
|
#sock-file = {DATA}/bot.sock
|
||||||
|
|
||||||
|
#log-levels = TRACE,INFO,WARN
|
||||||
|
|
||||||
# database - currently only supports sqlite3
|
# database - currently only supports sqlite3
|
||||||
#database = sqlite3:{DATA}/bot.db
|
#database = sqlite3:{DATA}/bot.db
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,10 @@ class HookedHandler(logging.StreamHandler):
|
||||||
class Log(object):
|
class Log(object):
|
||||||
_hooks: typing.List[typing.Callable[[int, str], None]]
|
_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 = []
|
self._hooks = []
|
||||||
|
|
||||||
logging.addLevelName(LEVELS["trace"], "TRACE")
|
logging.addLevelName(LEVELS["trace"], "TRACE")
|
||||||
|
@ -52,6 +55,7 @@ class Log(object):
|
||||||
self.logger.addHandler(hook_handler)
|
self.logger.addHandler(hook_handler)
|
||||||
|
|
||||||
if to_file:
|
if to_file:
|
||||||
|
if "TRACE" in file_levels:
|
||||||
trace_path = os.path.join(location, "trace.log")
|
trace_path = os.path.join(location, "trace.log")
|
||||||
trace_handler = logging.handlers.TimedRotatingFileHandler(
|
trace_handler = logging.handlers.TimedRotatingFileHandler(
|
||||||
trace_path, when="midnight", backupCount=5)
|
trace_path, when="midnight", backupCount=5)
|
||||||
|
@ -59,6 +63,7 @@ class Log(object):
|
||||||
trace_handler.setFormatter(formatter)
|
trace_handler.setFormatter(formatter)
|
||||||
self.logger.addHandler(trace_handler)
|
self.logger.addHandler(trace_handler)
|
||||||
|
|
||||||
|
if "INFO" in file_levels:
|
||||||
info_path = os.path.join(location, "info.log")
|
info_path = os.path.join(location, "info.log")
|
||||||
info_handler = logging.handlers.TimedRotatingFileHandler(
|
info_handler = logging.handlers.TimedRotatingFileHandler(
|
||||||
info_path, when="midnight", backupCount=1)
|
info_path, when="midnight", backupCount=1)
|
||||||
|
@ -66,6 +71,7 @@ class Log(object):
|
||||||
info_handler.setFormatter(formatter)
|
info_handler.setFormatter(formatter)
|
||||||
self.logger.addHandler(info_handler)
|
self.logger.addHandler(info_handler)
|
||||||
|
|
||||||
|
if "WARN" in file_levels:
|
||||||
warn_path = os.path.join(location, "warn.log")
|
warn_path = os.path.join(location, "warn.log")
|
||||||
warn_handler = logging.FileHandler(warn_path)
|
warn_handler = logging.FileHandler(warn_path)
|
||||||
warn_handler.setLevel(LEVELS["warn"])
|
warn_handler.setLevel(LEVELS["warn"])
|
||||||
|
|
Loading…
Reference in a new issue