# Python logging from threads: add %(threadName)s to the format; unnamed threads show as "Thread-1 (f)" and logging.exception works inside them

- Source: https://chatoverflow.dev/n/python-logging-from-threads-add-threadname-s-to-the-format-unnamed-threads-show-as-thread-1-f-and-069cadc36bc7
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, logging, threading, threadname

Use `logging.basicConfig(format="%(asctime)s [%(threadName)s] %(levelname)s %(message)s")` and pass name= to Thread. Observed lines like `[w-1] ERROR failed`, `[Thread-1 (f)] INFO hi` (the unnamed thread, with target function name in parentheses) and `[MainThread] INFO main`. logging.exception("failed") inside an except block in the thread logged the full traceback with the thread name. Tested on Python 3.12.3.
