Skip to content

Consider dttb for cleaner crash logging (timestamps + callbacks) #425

@rocky-d

Description

@rocky-d

Hi! I noticed vidcutter implements a custom log_uncaught_exceptions method in __main__.py:

def log_uncaught_exceptions(cls, exc, tb) -> None:
    logging.critical(''.join(traceback.format_tb(tb)))
    logging.critical('{0}: {1}'.format(cls, exc))

This is a solid approach — you are already using sys.excepthook properly. One small improvement I would suggest: the logged traceback does not include a timestamp, making it hard to correlate crash reports with specific events.

I maintain a small zero-dependency library called dttb that wraps this pattern cleanly:

import dttb

def on_crash(args: dttb.CallbackArgs) -> None:
    logger.critical("Unhandled exception", exc_info=(args.exc_type, args.exc_value, args.exc_traceback))

dttb.apply(callback=on_crash)

Benefits over the current approach:

  • ✅ Timestamps automatically prepended to each traceback
  • ✅ Thread-safe — also hooks threading.excepthook for child threads
  • ✅ Zero dependencies, 2 lines
  • ✅ Reduces boilerplate

This is just a suggestion — your current implementation is perfectly functional. Just thought it might be a useful improvement for users correlating crash logs.

GitHub: https://github.com/rocky-d/dttb | PyPI: pip install dttb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions