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)