log captured exceptions

Signed-off-by: vladmandic <mandic00@live.com>
pull/4599/head
vladmandic 2026-01-24 13:54:37 +01:00
parent a7c32caae3
commit 7bd73d6e75
4 changed files with 33 additions and 6 deletions

View File

@ -3,7 +3,7 @@
## Todo
- update `rocm/windows`
## Update for 2026-01-24
- **Features**
@ -23,7 +23,10 @@
- relocate all json data files to `data/` folder
existing data files are auto-migrated on startup
- further work on type consistency and type checking, thanks @awsr
- log captured exceptions
- add ui placeholders for future agent-scheduler work, thanks @ryanmeador
- implement abort system on repeated errors, thanks @awsr
currently used by lora and textual-inversion loaders
- update package requirements
- **Fixes**
- add video ui elem_ids, thanks @ryanmeador

@ -1 +1 @@
Subproject commit cdddbbd17ac0f49fc4fccd5fac2446940294ca40
Subproject commit 188dd69e7532f1d9db8174c8fcc67b47b2625aed

View File

@ -112,7 +112,7 @@ def install_traceback(suppress: list = []):
width = os.environ.get("SD_TRACEWIDTH", console.width if console else None)
if width is not None:
width = int(width)
traceback_install(
log.excepthook = traceback_install(
console=console,
extra_lines=int(os.environ.get("SD_TRACELINES", 1)),
max_frames=int(os.environ.get("SD_TRACEFRAMES", 16)),
@ -168,7 +168,6 @@ def setup_logging():
def get(self):
return self.buffer
class LogFilter(logging.Filter):
def __init__(self):
super().__init__()
@ -215,6 +214,23 @@ def setup_logging():
logging.Logger.trace = partialmethod(logging.Logger.log, logging.TRACE)
logging.trace = partial(logging.log, logging.TRACE)
def exception_hook(e: Exception, suppress=[]):
from rich.traceback import Traceback
tb = Traceback.from_exception(type(e), e, e.__traceback__, show_locals=False, max_frames=16, extra_lines=1, suppress=suppress, theme="ansi_dark", word_wrap=False, width=console.width)
# print-to-console, does not get printed-to-file
exc_type, exc_value, exc_traceback = sys.exc_info()
log.excepthook(exc_type, exc_value, exc_traceback)
# print-to-file, temporarily disable-console-handler
for handler in log.handlers.copy():
if isinstance(handler, RichHandler):
log.removeHandler(handler)
with console.capture() as capture:
console.print(tb)
log.critical(capture.get())
log.addHandler(rh)
log.traceback = exception_hook
level = logging.DEBUG if (args.debug or args.trace) else logging.INFO
log.setLevel(logging.DEBUG) # log to file is always at level debug for facility `sd`
log.print = rprint
@ -240,8 +256,10 @@ def setup_logging():
)
logging.basicConfig(level=logging.ERROR, format='%(asctime)s | %(name)s | %(levelname)s | %(module)s | %(message)s', handlers=[logging.NullHandler()]) # redirect default logger to null
pretty_install(console=console)
install_traceback()
while log.hasHandlers() and len(log.handlers) > 0:
log.removeHandler(log.handlers[0])
@ -288,7 +306,6 @@ def setup_logging():
logging.getLogger("torch").setLevel(logging.ERROR)
logging.getLogger("ControlNet").handlers = log.handlers
logging.getLogger("lycoris").handlers = log.handlers
# logging.getLogger("DeepSpeed").handlers = log.handlers
ts('log', t_start)

View File

@ -17,11 +17,18 @@ def install(suppress=[]):
def display(e: Exception, task: str, suppress=[]):
log.error(f"{task or 'error'}: {type(e).__name__}")
if isinstance(e, ErrorLimiterAbort):
return
log.critical(f"{task or 'error'}: {type(e).__name__}")
"""
trace = traceback.format_exc()
log.error(trace)
for line in traceback.format_tb(e.__traceback__):
log.error(repr(line))
console = get_console()
console.print_exception(show_locals=False, max_frames=16, extra_lines=1, suppress=suppress, theme="ansi_dark", word_wrap=False, width=console.width)
"""
log.traceback(e, suppress=suppress)
def display_once(e: Exception, task):