Closed dbast closed 4 months ago
yay. green.
rebased
rebased
I'm torn on the concept of logging between:
My worry is that currently, the sdcard is mounted if the user left it in. Add human error (like me not paying attention to remove logging of a mnemonic and passphrase to a debug log before submitting a pr... and it makes it into a persisted file, plus human error like others not paying attention and it gets merged.
Thank you for all of your great prs... and in advance for settling my paranoid (because I don't know better) nerves.
@jdlcdl right... both the existing print statements AND the new logging statements can be problematic IF the console output (stdout/stderr) is redirected to a file on sd-card:
logging.basicConfig
anymore) and a added unit test ensures that the logging framework is setup to write to stderr
.logging
framework over plain print
statements: one can de/activate log messages without un-commenting / commenting-out code, by running the main.py via e.g. main.py -l ERROR
(no output as all current logger calls are on INFO level) or main.py -l DEBUG
(more output, in case we convert the currently commented out print statements to logger.debug(msg)
calls, not done by this PR).The help message got update to contain a warning in case one changes the default loglevel from INFO to something else:
usage: main.py [-h] [-l {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}]
options:
-h, --help show this help message and exit
-l {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}, --loglevel {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}
Set the log level (default: INFO), WARNING: changing the log level to something more verbose than
INFO may result in unwanted data being written to stderr
Logging > print: ACK
Recommend we drop mention of FATAL
in the usage and standardize on CRITICAL
.
see: https://stackoverflow.com/a/31170408/11611893
Later TODO: Provide explicit style / convention guidance for devs in a README.
One thing I can't think through is: what kinds of logging should be INFO vs DEBUG? I think the question is a bit different for us than typical projects since our devs are the only ones who'll ever see any of these messages. So in that sense, EVERY log line is intended to aid debugging.
I guess for now the best we can do is default to INFO and then over time make decisions about what log chatter we want to quiet down and demote to DEBUG.
Also filter out WARN
?
Moving main.py
is only successful if the setup has already run python -m pip install -e .
(which is not currently in our local dev setup steps in raspberry_pi_os_build_instructions.md; I don't know how SeedSigner OS is setup).
Because main.py
is importing from the seedsigner.controller
package, EITHER main.py
has to sit above the seedsigner
package / dir OR the seedsigner
module needs to be globally available to import.
I also dislike symlinks in repos in general.
Moving main.py
was caused by the desire to add these new tests to the test suite. With maybe the exception of verifying the stderr
writes, I don't think the tests are necessary. We don't need to test argparse
module's basic functionality and I can live without verifying the log level. Even the verification of stderr
is maybe arguably just testing the logging
module itself.
I'm reading up on logging.ini
configs now. Having the output explicitly stated there (plus some other needed config, e.g. silencing PIL) tentatively feels preferable.
@kdmukai Added another commit that 1. moves the main.py back 2. eliminates the introduced symlink 3. still gets the added tests working by doing an import trick :)
I cautiously converted all existing print statements to logging.info
and set the INFO
log level as default log level to mimic the current behaviour of the print statements... further PRs can then refine the level of each message and also enable the currently commented-out print statements on e.g. debug level.... this PR is intended more on finding agreement regarding the overall concept
Final minor nits noted above, but otherwise very happy to ACK this!
Very nice quality-of-life improvement here, @dbast.
tACK. Great contribution as usual @dbast!
seedsigner
cli entrypoint for main as that becomes possible with the main.py move.logger.info
calls (INFO is the default log level)2024-05-15 17:21:45.385 INFO: Starting Seedsigner with: {'loglevel': 'INFO'}
There are many many commented out
print
statements in the code base that could be converted tologger.debug(...)
calls and thus be shown additionally via runningmain.py -l DEBUG
, but that is for next PRs as all those commented out print statements can be potential broken by referencing non existing variables etc.This is a move towards more Pythonic ways of doing: The logging framework with its central configurability, options to set levels, the ability to activate certain log lines by choosing a different log level (without un-commenting/commenting print statements), the possibility to the see how much times is between log calls (without extra instrumenting the code) etc is all in all very convenient.
The help output on cli:
Description
Describe the change simply. Provide a reason for the change.
Include screenshots of any new or modified screens (or at least explain why they were omitted)
This pull request is categorized as a:
Checklist
pytest
and made sure all unit tests pass before sumbitting the PRIf you modified or added functionality/workflow, did you add new unit tests?
I have tested this PR on the following platforms/os:
Note: Keep your changes limited in scope; if you uncover other issues or improvements along the way, ideally submit those as a separate PR. The more complicated the PR the harder to review, test, and merge.