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]:
|
if 'client_nickname' in event[0]:
|
||||||
displayname = event[0]['client_nickname']
|
displayname = event[0]['client_nickname']
|
||||||
else:
|
elif 'clid' in event[0]:
|
||||||
displayname = event[0]['clid']
|
displayname = event[0]['clid']
|
||||||
|
else:
|
||||||
|
self.pipeOut(event[0])
|
||||||
|
displayname = "Unresolved"
|
||||||
|
|
||||||
self.pipeOut(f"Client [{displayname}] connected.")
|
self.pipeOut(f"Client [{displayname}] connected.")
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[Connection]
|
[Connection]
|
||||||
host = "example.com"
|
host = "127.0.0.1"
|
||||||
port = 10011
|
port = 10011
|
||||||
sid = 1
|
sid = 1
|
||||||
|
|
||||||
|
|
13
src/util.py
13
src/util.py
|
@ -14,7 +14,7 @@ import sys
|
||||||
import shutil
|
import shutil
|
||||||
import os.path
|
import os.path
|
||||||
import logging
|
import logging
|
||||||
from datetime import date
|
from logging.handlers import RotatingFileHandler
|
||||||
|
|
||||||
# Custom
|
# Custom
|
||||||
import toml
|
import toml
|
||||||
|
@ -59,13 +59,16 @@ def getconf(fname):
|
||||||
|
|
||||||
def setupLogger(lvl="DEBUG"):
|
def setupLogger(lvl="DEBUG"):
|
||||||
"""
|
"""
|
||||||
|
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()
|
||||||
now = date.today().strftime("%Y-%m-%d")
|
logpath = r".\log\myTS3.log"
|
||||||
handler = logging.FileHandler(f"myTS3_{now}.log", encoding="utf-8")
|
if not os.path.exists(os.path.dirname(logpath)):
|
||||||
logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%d-%m-%Y %H:%M:%S")
|
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)
|
handler.setFormatter(logformat)
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
log.setLevel(lvl)
|
log.setLevel(lvl)
|
||||||
|
|
Loading…
Reference in New Issue