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 random*.txt
quotes.txt quotes.txt
tts.zip 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`. 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 ## [1.8.0] - 2022-10-23
### Added 1.8.0 ### Added 1.8.0
* Option to disable TTS audio output for !wiki function * Option to disable TTS audio output for !wiki function
* Option to configure the number of sentences fetched by !wiki function * Option to configure the number of sentences fetched by !wiki function
* !wikitoff command * !wtoff command
* !wikiton command * !wton command
### Changed 1.8.0 ### 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 urllib.error import HTTPError
from http.server import HTTPServer, BaseHTTPRequestHandler from http.server import HTTPServer, BaseHTTPRequestHandler
from socketserver import ThreadingMixIn from socketserver import ThreadingMixIn
from logging.handlers import RotatingFileHandler
import yaml import yaml
import requests import requests
@ -1571,6 +1572,13 @@ def load_config():
return CONF return CONF
def exceptionlog(etype, evalue, traceback):
""" Log Exceptions to file """
logging.error(
"Logging an uncaught exception",
exc_info=(etype, evalue, traceback)
)
def main(): def main():
""" Main loop """ """ Main loop """
@ -1578,7 +1586,12 @@ def main():
CONF = load_config() CONF = load_config()
lastreload = datetime.datetime.now() 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': if CONF['LOG_LEVEL'] == 'DEBUG':
sys.tracebacklimit = 5 sys.tracebacklimit = 5
@ -1646,10 +1659,20 @@ def main():
os.kill(os.getpid(), signal.SIGTERM) os.kill(os.getpid(), signal.SIGTERM)
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig( logFormatter = logging.Formatter(
level=logging.DEBUG, "%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s"
format='%(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 sys.tracebacklimit = 3