Added logging to file

This commit is contained in:
gpkvt 2022-10-23 22:09:44 +02:00
parent d962bd2570
commit d5389d6de3
4 changed files with 37 additions and 6 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ tts.spec
random*.txt
quotes.txt
tts.zip
tts.log
tts.log.?

View File

@ -2,14 +2,20 @@
All notable changes to this project will be documented in this file. If there is a `Changed` section please read carefully, as this often means that you will need to adapt your `config.yml`.
## [1.8.1] - 2022-10-23
### Added 1.8.1
* Added logging to file
## [1.8.0] - 2022-10-23
### Added 1.8.0
* Option to disable TTS audio output for !wiki function
* Option to configure the number of sentences fetched by !wiki function
* !wikitoff command
* !wikiton command
* !wtoff command
* !wton command
### Changed 1.8.0

BIN
tts.exe

Binary file not shown.

31
tts.py
View File

@ -38,6 +38,7 @@ from urllib.parse import parse_qs
from urllib.error import HTTPError
from http.server import HTTPServer, BaseHTTPRequestHandler
from socketserver import ThreadingMixIn
from logging.handlers import RotatingFileHandler
import yaml
import requests
@ -1571,6 +1572,13 @@ def load_config():
return CONF
def exceptionlog(etype, evalue, traceback):
""" Log Exceptions to file """
logging.error(
"Logging an uncaught exception",
exc_info=(etype, evalue, traceback)
)
def main():
""" Main loop """
@ -1578,7 +1586,12 @@ def main():
CONF = load_config()
lastreload = datetime.datetime.now()
logging.getLogger().setLevel(CONF['LOG_LEVEL'])
for handler in rootLogger.handlers:
if isinstance(handler, logging.StreamHandler):
handler.setLevel(CONF['LOG_LEVEL'])
sys.excepthook = exceptionlog
if CONF['LOG_LEVEL'] == 'DEBUG':
sys.tracebacklimit = 5
@ -1646,10 +1659,20 @@ def main():
os.kill(os.getpid(), signal.SIGTERM)
if __name__ == "__main__":
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s'
logFormatter = logging.Formatter(
"%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s"
)
rootLogger = logging.getLogger()
fileHandler = RotatingFileHandler("tts.log", backupCount=9)
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
fileHandler.doRollover()
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
rootLogger.level = logging.DEBUG
sys.tracebacklimit = 3