add rotating log handler
This commit is contained in:
parent
659dfd551c
commit
c5c265d3a0
5
myTS3.py
5
myTS3.py
|
@ -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.")
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[Connection]
|
||||
host = "example.com"
|
||||
host = "127.0.0.1"
|
||||
port = 10011
|
||||
sid = 1
|
||||
|
||||
|
|
13
src/util.py
13
src/util.py
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue