From 954593258ce362c18d278f1754521cd755ac0ba3 Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 27 Sep 2021 13:21:00 +0200 Subject: [PATCH] fix logpath for real --- myTS3.py | 4 +++- src/util.py | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/myTS3.py b/myTS3.py index 94e9f56..31b9fe1 100644 --- a/myTS3.py +++ b/myTS3.py @@ -12,6 +12,7 @@ __status__ = "Development" import sys import time import json +import os.path # Custom import ts3 @@ -480,7 +481,8 @@ class TSbot: def main(): # Start logger - log = util.setupLogger() + logpath = os.path.dirname(os.path.abspath(__file__)) + r"\log" + log = util.setupLogger(logpath) # Log unhandled exception sys.excepthook = util.unhandledException diff --git a/src/util.py b/src/util.py index 8ea8057..a5b4c00 100644 --- a/src/util.py +++ b/src/util.py @@ -57,17 +57,16 @@ def getconf(fname): exit(1) -def setupLogger(lvl="DEBUG"): +def setupLogger(logpath, lvl="DEBUG"): """ Create a rotating log in a log folder """ global log # Needed to log exceptions in src\util log = logging.getLogger() - logpath = os.path.dirname(os.path.abspath(__file__)) + r"\log\myTS3.log" - if not os.path.exists(os.path.dirname(logpath)): - os.makedirs(os.path.dirname(logpath)) - handler = RotatingFileHandler(logpath, encoding='utf-8', maxBytes=5*1024*1024, backupCount=10) + if not os.path.exists(logpath): + os.makedirs(logpath) + handler = RotatingFileHandler(logpath + r"\myTS3.log", encoding='utf-8', maxBytes=5*1024*1024, backupCount=10) logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%Y-%m-%d %H:%M:%S") handler.setFormatter(logformat) log.addHandler(handler)