-
Notifications
You must be signed in to change notification settings - Fork 88
Add centralized logger. #1031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add centralized logger. #1031
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e8d09cd
Add centralized logger.
jverswijver f2a7692
Flake8 😡
jverswijver dc96601
convert test.
jverswijver c5f11c2
Small tweaks to logging.
jverswijver 7a66d51
update changelog
jverswijver a52b789
update nginx
jverswijver 3e1df5d
apply suggestions from code review.
jverswijver 0274a23
apply suggestions from code review.
jverswijver 6fd5859
update changelogs.
jverswijver 1daa944
update changelog.
jverswijver 42425a4
apply suggestions from code review
jverswijver c8833d7
apply suggestions from code review.
jverswijver 5b96445
bump version
jverswijver f341d54
apply suggestions from code review.
jverswijver 5cd9f0b
add additional logging for populate1
jverswijver c0248db
Merge branch 'master' into add_logger
guzman-raphael 5d4d625
apply suggestions from code review.
jverswijver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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() | ||
guzman-raphael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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): | ||
guzman-raphael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.