-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from dbast/logging
Setup Python logging + convert print statements to logger calls
- Loading branch information
Showing
18 changed files
with
170 additions
and
51 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
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 %(levelname)8s [%(name)s %(funcName)s (%(lineno)d)]: %(message)s") | ||
) | ||
root_logger.addHandler(console_handler) | ||
|
||
# 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__}") | ||
|
||
# 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.