'bot.log' -> 'trace.log' and add a 'warn.log' log file that only catches

warn-and-worse
This commit is contained in:
jesopo 2018-11-26 11:09:43 +00:00
parent 5b70f37796
commit 8cd069d37d
2 changed files with 13 additions and 8 deletions

View file

@ -43,11 +43,16 @@ class Log(object):
stdout_handler.setFormatter(formatter) stdout_handler.setFormatter(formatter)
self.logger.addHandler(stdout_handler) self.logger.addHandler(stdout_handler)
file_handler = logging.handlers.TimedRotatingFileHandler( trace_handler = logging.handlers.TimedRotatingFileHandler(
location, when="midnight", backupCount=5) os.path.join(location, "trace.log"), when="midnight", backupCount=5)
file_handler.setLevel(LEVELS["trace"]) trace_handler.setLevel(LEVELS["trace"])
file_handler.setFormatter(formatter) trace_handler.setFormatter(formatter)
self.logger.addHandler(file_handler) 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)
def trace(self, message: str, params: typing.List, **kwargs): def trace(self, message: str, params: typing.List, **kwargs):
self._log(message, params, LEVELS["trace"], kwargs) self._log(message, params, LEVELS["trace"], kwargs)

View file

@ -17,9 +17,9 @@ arg_parser.add_argument("--database", "-d",
help="Location of the sqlite3 database file", help="Location of the sqlite3 database file",
default=os.path.join(directory, "databases", "bot.db")) default=os.path.join(directory, "databases", "bot.db"))
arg_parser.add_argument("--log", "-l", arg_parser.add_argument("--log-dir", "-l",
help="Location of the main log file", help="Location of the log directory",
default=os.path.join(directory, "logs", "bot.log")) default=os.path.join(directory, "logs"))
arg_parser.add_argument("--add-server", "-a", arg_parser.add_argument("--add-server", "-a",
help="Add a new server", action="store_true") help="Add a new server", action="store_true")