Implement stackprinter
This commit is contained in:
parent
693e8f195d
commit
bd9c8a84b9
44
app/log.py
44
app/log.py
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
import stackprinter
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
@ -55,25 +56,32 @@ stderr.addFilter(local_filter)
|
|||||||
stderr.addFilter(debug_filter)
|
stderr.addFilter(debug_filter)
|
||||||
|
|
||||||
# create formatter and add it to the handlers
|
# create formatter and add it to the handlers
|
||||||
stderr_fmt = logging.Formatter('[%(asctime)s] %(leveltag)s: %(message)s',
|
# stderr_fmt = logging.Formatter('[%(asctime)s] %(leveltag)s: %(message)s',
|
||||||
datefmt='%H:%M:%S')
|
# datefmt='%H:%M:%S')
|
||||||
syslog_fmt = logging.Formatter(
|
# syslog_fmt = logging.Formatter(
|
||||||
'[%(name)s] %(module)s.%(funcName)s - %(leveltag)s: %(message)s'
|
# '[%(name)s] %(module)s.%(funcName)s - %(leveltag)s: %(message)s'
|
||||||
)
|
# )
|
||||||
stderr.setFormatter(stderr_fmt)
|
# stderr.setFormatter(stderr_fmt)
|
||||||
syslog.setFormatter(syslog_fmt)
|
# syslog.setFormatter(syslog_fmt)
|
||||||
|
|
||||||
|
|
||||||
|
class VerboseExceptionFormatter(logging.Formatter):
|
||||||
|
def formatException(self, exc_info):
|
||||||
|
msg = stackprinter.format(exc_info)
|
||||||
|
lines = msg.split('\n')
|
||||||
|
lines_indented = [" ┆ " + line + "\n" for line in lines]
|
||||||
|
msg_indented = "".join(lines_indented)
|
||||||
|
return msg_indented
|
||||||
|
|
||||||
|
|
||||||
|
stderr_fmt = '[%(asctime)s] %(leveltag)s: %(message)s'
|
||||||
|
stderr_formatter = VerboseExceptionFormatter(stderr_fmt, datefmt='%H:%M:%S')
|
||||||
|
stderr.setFormatter(stderr_formatter)
|
||||||
|
|
||||||
|
syslog_fmt = '[%(name)s] %(module)s.%(funcName)s - %(leveltag)s: %(message)s'
|
||||||
|
syslog_formatter = VerboseExceptionFormatter(syslog_fmt)
|
||||||
|
syslog.setFormatter(syslog_formatter)
|
||||||
|
|
||||||
# add the handlers to the log
|
# add the handlers to the log
|
||||||
log.addHandler(stderr)
|
log.addHandler(stderr)
|
||||||
log.addHandler(syslog)
|
log.addHandler(syslog)
|
||||||
|
|
||||||
|
|
||||||
def log_uncaught_exceptions(ex_cls, ex, tb):
|
|
||||||
|
|
||||||
print("\033[1;31;47m")
|
|
||||||
logging.critical(''.join(traceback.format_tb(tb)))
|
|
||||||
print("\033[1;37;40m")
|
|
||||||
logging.critical('{0}: {1}'.format(ex_cls, ex))
|
|
||||||
|
|
||||||
|
|
||||||
sys.excepthook = log_uncaught_exceptions
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from log import log
|
from log import log
|
||||||
import argparse
|
import argparse
|
||||||
|
import stackprinter
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@ -1557,6 +1558,13 @@ if __name__ == "__main__":
|
|||||||
win = Window()
|
win = Window()
|
||||||
win.show()
|
win.show()
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
msg = "Unhandled Exception caught by musicmuster.main()"
|
from helpers import send_mail
|
||||||
log.exception(msg, exc_info=True, stack_info=True)
|
|
||||||
|
msg = stackprinter.format(exc)
|
||||||
|
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
|
||||||
|
"Exception from musicmuster", msg)
|
||||||
|
|
||||||
|
print("\033[1;31;47mUnhandled exception starts\033[1;37;40m")
|
||||||
|
stackprinter.show(style="darkbg2")
|
||||||
|
print("\033[1;31;47mUnhandled exception ends\033[1;37;40m")
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import stackprinter
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@ -1954,8 +1955,10 @@ class PlaylistTab(QTableWidget):
|
|||||||
# FIXME temporary workaround to issue #147
|
# FIXME temporary workaround to issue #147
|
||||||
try:
|
try:
|
||||||
self.item(playlist_row.row_number, column).setText(new_text)
|
self.item(playlist_row.row_number, column).setText(new_text)
|
||||||
except AttributeError:
|
except AttributeError as exc:
|
||||||
msg = f"Issue 147 occurred. {playlist_row=}, {additional_text=}"
|
msg = f"Issue 147 occurred. {playlist_row=}, {additional_text=}"
|
||||||
|
msg += "\n\n"
|
||||||
|
msg += stackprinter.format(exc)
|
||||||
helpers.send_mail(Config.ERRORS_TO, Confit.ERRORS_FROM,
|
helpers.send_mail(Config.ERRORS_TO, Confit.ERRORS_FROM,
|
||||||
"Issue #147 from musicmuster", msg)
|
"Issue #147 from musicmuster", msg)
|
||||||
|
|
||||||
|
|||||||
11
poetry.lock
generated
11
poetry.lock
generated
@ -624,6 +624,14 @@ pure-eval = "*"
|
|||||||
[package.extras]
|
[package.extras]
|
||||||
tests = ["pytest", "typeguard", "pygments", "littleutils", "cython"]
|
tests = ["pytest", "typeguard", "pygments", "littleutils", "cython"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stackprinter"
|
||||||
|
version = "0.2.10"
|
||||||
|
description = "Debug-friendly stack traces, with variable values and semantic highlighting"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "text-unidecode"
|
name = "text-unidecode"
|
||||||
version = "1.3"
|
version = "1.3"
|
||||||
@ -708,7 +716,7 @@ python-versions = "*"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.9"
|
python-versions = "^3.9"
|
||||||
content-hash = "91e055875df86707e1ce1544b1d29126265011d750897912daa37af3fe005498"
|
content-hash = "0fdda77377246e18b5e85459fa2c26173f14467f32e71c576b30fa0899ced8b0"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
alembic = [
|
alembic = [
|
||||||
@ -1073,6 +1081,7 @@ stack-data = [
|
|||||||
{file = "stack_data-0.2.0-py3-none-any.whl", hash = "sha256:999762f9c3132308789affa03e9271bbbe947bf78311851f4d485d8402ed858e"},
|
{file = "stack_data-0.2.0-py3-none-any.whl", hash = "sha256:999762f9c3132308789affa03e9271bbbe947bf78311851f4d485d8402ed858e"},
|
||||||
{file = "stack_data-0.2.0.tar.gz", hash = "sha256:45692d41bd633a9503a5195552df22b583caf16f0b27c4e58c98d88c8b648e12"},
|
{file = "stack_data-0.2.0.tar.gz", hash = "sha256:45692d41bd633a9503a5195552df22b583caf16f0b27c4e58c98d88c8b648e12"},
|
||||||
]
|
]
|
||||||
|
stackprinter = []
|
||||||
text-unidecode = []
|
text-unidecode = []
|
||||||
thefuzz = []
|
thefuzz = []
|
||||||
tinytag = [
|
tinytag = [
|
||||||
|
|||||||
@ -23,6 +23,7 @@ thefuzz = "^0.19.0"
|
|||||||
python-Levenshtein = "^0.12.2"
|
python-Levenshtein = "^0.12.2"
|
||||||
pyfzf = "^0.3.1"
|
pyfzf = "^0.3.1"
|
||||||
pydymenu = "^0.5.2"
|
pydymenu = "^0.5.2"
|
||||||
|
stackprinter = "^0.2.10"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
ipdb = "^0.13.9"
|
ipdb = "^0.13.9"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user