fix logpath for real

This commit is contained in:
Lukas 2021-09-27 13:21:00 +02:00
parent aed1a85b20
commit 954593258c
2 changed files with 7 additions and 6 deletions

View File

@ -12,6 +12,7 @@ __status__ = "Development"
import sys import sys
import time import time
import json import json
import os.path
# Custom # Custom
import ts3 import ts3
@ -480,7 +481,8 @@ class TSbot:
def main(): def main():
# Start logger # Start logger
log = util.setupLogger() logpath = os.path.dirname(os.path.abspath(__file__)) + r"\log"
log = util.setupLogger(logpath)
# Log unhandled exception # Log unhandled exception
sys.excepthook = util.unhandledException sys.excepthook = util.unhandledException

View File

@ -57,17 +57,16 @@ def getconf(fname):
exit(1) exit(1)
def setupLogger(lvl="DEBUG"): def setupLogger(logpath, lvl="DEBUG"):
""" """
Create a rotating log in a log folder Create a rotating log in a log folder
""" """
global log # Needed to log exceptions in src\util global log # Needed to log exceptions in src\util
log = logging.getLogger() log = logging.getLogger()
logpath = os.path.dirname(os.path.abspath(__file__)) + r"\log\myTS3.log" if not os.path.exists(logpath):
if not os.path.exists(os.path.dirname(logpath)): os.makedirs(logpath)
os.makedirs(os.path.dirname(logpath)) handler = RotatingFileHandler(logpath + r"\myTS3.log", encoding='utf-8', maxBytes=5*1024*1024, backupCount=10)
handler = RotatingFileHandler(logpath, encoding='utf-8', maxBytes=5*1024*1024, backupCount=10)
logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%Y-%m-%d %H:%M:%S") logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%Y-%m-%d %H:%M:%S")
handler.setFormatter(logformat) handler.setFormatter(logformat)
log.addHandler(handler) log.addHandler(handler)