forked from datajoint/datajoint-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.py
More file actions
26 lines (16 loc) · 687 Bytes
/
logging.py
File metadata and controls
26 lines (16 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import logging
import os
import sys
logger = logging.getLogger(__name__.split(".")[0])
log_level = os.getenv("DJ_LOG_LEVEL", "info").upper()
log_format = logging.Formatter("[%(asctime)s][%(levelname)s]: %(message)s")
stream_handler = logging.StreamHandler() # default handler
stream_handler.setFormatter(log_format)
logger.setLevel(level=log_level)
logger.handlers = [stream_handler]
def excepthook(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
sys.excepthook = excepthook