add rotating log handler

This commit is contained in:
Lukas 2021-09-27 13:03:32 +02:00
parent 659dfd551c
commit c5c265d3a0
3 changed files with 13 additions and 7 deletions

View File

@ -131,8 +131,11 @@ class TSbot:
if 'client_nickname' in event[0]:
displayname = event[0]['client_nickname']
else:
elif 'clid' in event[0]:
displayname = event[0]['clid']
else:
self.pipeOut(event[0])
displayname = "Unresolved"
self.pipeOut(f"Client [{displayname}] connected.")

View File

@ -1,5 +1,5 @@
[Connection]
host = "example.com"
host = "127.0.0.1"
port = 10011
sid = 1

View File

@ -14,7 +14,7 @@ import sys
import shutil
import os.path
import logging
from datetime import date
from logging.handlers import RotatingFileHandler
# Custom
import toml
@ -59,13 +59,16 @@ def getconf(fname):
def setupLogger(lvl="DEBUG"):
"""
Create a rotating log in a log folder
"""
global log # Needed to log exceptions in src\util
log = logging.getLogger()
now = date.today().strftime("%Y-%m-%d")
handler = logging.FileHandler(f"myTS3_{now}.log", encoding="utf-8")
logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%d-%m-%Y %H:%M:%S")
logpath = 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)
logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%Y-%m-%d %H:%M:%S")
handler.setFormatter(logformat)
log.addHandler(handler)
log.setLevel(lvl)