-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathdebug.py
More file actions
21 lines (17 loc) · 661 Bytes
/
debug.py
File metadata and controls
21 lines (17 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# tests/debug.py
import tracemalloc
import logging
import warnings
import sys
import traceback
# Enable Tracemalloc
tracemalloc.start()
# Configure Logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)d - %(message)s')
# Function to Log Warnings with Traceback
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
log = file if hasattr(file, 'write') else sys.stderr
traceback.print_stack(file=log)
log.write(warnings.formatwarning(message, category, filename, lineno, line))
# Override showwarning
warnings.showwarning = warn_with_traceback