-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add_logger' of https://github.com/jverswijver/datajoint…
…-python into loggerPR
- Loading branch information
Showing
20 changed files
with
144 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
import os | ||
import sys | ||
import io | ||
|
||
logger = logging.getLogger(__name__.split(".")[0]) | ||
|
||
log_level = os.environ.get("DJ_LOG_LEVEL", "warning").upper() | ||
|
||
log_format = logging.Formatter( | ||
"[%(asctime)s][%(funcName)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 | ||
|
||
if logger.getEffectiveLevel() == 10: | ||
logger.debug( | ||
"Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback) | ||
) | ||
else: | ||
logger.error(f"Uncaught exception: {exc_value}") | ||
|
||
|
||
sys.excepthook = excepthook | ||
|
||
|
||
# https://github.com/tqdm/tqdm/issues/313#issuecomment-267959111 | ||
class TqdmToLogger(io.StringIO): | ||
""" | ||
Output stream for TQDM which will output to logger module instead of | ||
the StdOut. | ||
""" | ||
|
||
logger = None | ||
level = None | ||
buf = "" | ||
|
||
def __init__(self, logger, level=None): | ||
super(TqdmToLogger, self).__init__() | ||
self.logger = logger | ||
self.level = level or logging.INFO | ||
|
||
def write(self, buf): | ||
self.buf = buf.strip("\r\n\t ") | ||
|
||
def flush(self): | ||
self.logger.log(self.level, self.buf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.