-
Notifications
You must be signed in to change notification settings - Fork 178
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
Setup Python logging + convert print statements to logger calls #558
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8e9c120
Setup Python logging + convert print statements to logger calls
dbast 94dc795
Warn about log level changes in cli arg description
dbast 5881a6e
Test that logging actually writes to stderr
dbast 2d9960e
Replace logging.basicConfig with explicit calls
dbast 3ff2951
Move back main.py
dbast af2cdf8
Add possibility to set per module default log levels
dbast f2ae4bb
Use human readable loglevel names in test
dbast 0c9d955
Remove separator line
dbast 19c4d1f
Add newline to back_stack logging
dbast 5a4ae50
Refine logformat
dbast c13a8b8
Update test
dbast 44d92c9
Merge remote-tracking branch 'origin/dev' into logging
dbast d088fbd
Improve test maintainability, camel case
dbast 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 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 |
---|---|---|
@@ -1,4 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
|
||
from seedsigner.controller import Controller | ||
|
||
# Get the one and only Controller instance and start our main loop | ||
Controller.get_instance().start() | ||
logger = logging.getLogger(__name__) | ||
|
||
DEFAULT_MODULE_LOG_LEVELS = { | ||
"PIL": logging.WARNING, | ||
# "seedsigner.gui.toast": logging.DEBUG, # example of more specific submodule logging config | ||
} | ||
|
||
|
||
def main(sys_argv=None): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-l", | ||
"--loglevel", | ||
choices=list((logging._nameToLevel.keys())), | ||
default="INFO", | ||
type=str, | ||
help=( | ||
"Set the log level (default: %(default)s), WARNING: changing the log level " | ||
"to something more verbose than %(default)s may result in unwanted data " | ||
"being written to stderr" | ||
), | ||
) | ||
|
||
args = parser.parse_args(sys_argv) | ||
|
||
root_logger = logging.getLogger() | ||
root_logger.setLevel(logging.getLevelName(args.loglevel)) | ||
console_handler = logging.StreamHandler(sys.stderr) | ||
console_handler.setFormatter( | ||
logging.Formatter("%(asctime)s.%(msecs)03d %(levelname)s:\t%(message)s") | ||
) | ||
root_logger.addHandler(console_handler) | ||
|
||
dbast marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Set log levels for specific modules | ||
for module, level in DEFAULT_MODULE_LOG_LEVELS.items(): | ||
logging.getLogger(module).setLevel(level) | ||
|
||
logger.info(f"Starting Seedsigner with: {args.__dict__}") | ||
dbast marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Get the one and only Controller instance and start our main loop | ||
Controller.get_instance().start() | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the
.%(msecs)03d
is redundant asasctime
includes millis already.I'd find something like this format more useful:
"%(asctime)s %(levelname)5s [%(name)s %(funcName)s (%(lineno)d)]: %(message)s"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh. thanks for the redundant msec finding, don't know why i didn't see that... this seems to have changed, I remember that is was required when working with older Python versions... having msecs help to accurately see how much time is required between certain calls.
Good idea to add funcname + lineno etc to the log line... (I am used to have all those fields via json loggers, which are not feasible here for the console) ... went for
"%(asctime)s %(levelname)8s [%(name)s %(funcName)s (%(lineno)d)]: %(message)s"
(=changed the 5s to 8s spacing so that all the potential loglevel are right aligned .. longest name isCRITICAL
), see 5a4ae50