Logging/emitters refactoring#1103
Conversation
Codecov Report
@@ Coverage Diff @@
## sekanjabin #1103 +/- ##
==============================================
+ Coverage 82% 83.39% +1.38%
==============================================
Files 72 71 -1
Lines 9733 9704 -29
==============================================
+ Hits 7982 8093 +111
+ Misses 1751 1611 -140
Continue to review full report at Codecov.
|
|
(Sorry, forgot to set it as draft, please consider it to be one) |
952086a to
ebb5840
Compare
ebb5840 to
ee12071
Compare
966757a to
289c716
Compare
derekpierre
left a comment
There was a problem hiding this comment.
Good refactor. I really like the emitter calls, they are much cleaner. Some comments mostly around the use of emitter.error.
I guess one catch was that we have to pass emitters to some functions. Is there a way around this? Even if not, I'm still pro this PR.
nucypher/cli/actions.py
Outdated
| def select_client_account(blockchain, prompt: str = None, default=0) -> str: | ||
| enumerated_accounts = dict(enumerate(blockchain.client.accounts)) | ||
| for index, account in enumerated_accounts.items(): | ||
| click.secho(f"{index} | {account}") |
There was a problem hiding this comment.
Presumably, this line and similar lines in the other methods below should be using the emitter instead? I guess this change was part of a merge, after your changes...
There was a problem hiding this comment.
These functions are called outside of the scope of NucypherClickConfig, so I'm not sure what to do with them. I suppose an emitter can be created in deploy() and passed to them.
| raise | ||
| else: | ||
| click.secho(str(e), fg='red', bold=True) | ||
| emitter.echo(str(e), color='red', bold=True) |
There was a problem hiding this comment.
Is the reason we don't want to simply log using emitter.error because of verbosity and color? There is an associated comment for the emitter.error method to allow colour to be specified as a parameter, would verbosity make sense as well? - default verbosity would be 1, but could be specified otherwise.
There was a problem hiding this comment.
I didn't want to overcomplicate the PR and only limit it to global changes. The next one would eliminate explicit color/boldness specification in emitter calls and use some semantic marking instead.
|
|
||
| else: | ||
| raise ValueError('Either "response" dict or "message" str is required, but got neither.') | ||
| def error(self, e): |
There was a problem hiding this comment.
Should we allow colour to be specified as a parameter for error logging? - red can be default. Should bold=True also be the default.
There was a problem hiding this comment.
I would prefer to avoid that, see above (and TODO in the PR description). I would rather eliminate all explicit style specification from the code, since it is hard to synchronize it between people, and you can never be sure whether to use red, or green, or some other color in some specific case - semantic calls like error() or warning() are more clear.
| raise | ||
| else: | ||
| click.secho(str(e), fg='red', bold=True) | ||
| emitter.echo(str(e), color='red', bold=True) |
There was a problem hiding this comment.
Same comment about emitter.error as above.
| raise | ||
| else: | ||
| click.secho(str(e), fg='red', bold=True) | ||
| emitter.echo(str(e), color='red', bold=True) |
There was a problem hiding this comment.
My plan for this PR was to just switch to explicit emitter usage without changing any related calls (to make sure I'm not changing the logging behavior - e.g. error() would log the error, while echo() doesn't). We can discuss any changes to logging strategies later when we get the blocking changes out of the way.
| raise ValueError('Either "response" dict or "message" str is required, but got neither.') | ||
| def error(self, e): | ||
| if self.verbosity >= 1: | ||
| e_str = str(e) |
There was a problem hiding this comment.
Would it make sense to add the class name of the error as well? i.e. e.__class__.__name__. Without it we are hoping that the message alone provides sufficient context.
There was a problem hiding this comment.
As above, this PR intends to change the emitter API while preserving the current behavior (because I'm still not sure what kind of logic is needed in different cases).
| try: | ||
| blockchain.connect(fetch_registry=False, sync_now=sync) | ||
| except BlockchainDeployerInterface.ConnectionFailed as e: | ||
| emitter.echo(str(e), color='red', bold=True) |
b40edc4 to
8a16b37
Compare
…ties/logging Also add a check that Sentry SDK is only initialized once
…ng to NucypherClickConfig
There's was not much happening between the beginning of start() and echo(), so moving the status printing should not obscure anything.
…gate it everywhere
…and add specific options for each type of logging Now quiet/verbose govern console output (emitters)
8a16b37 to
cc93cce
Compare
cc93cce to
84e1f49
Compare
A reworked PR #1079, branched off the current
croquetas, since there were a lot of changes introduced there.Changes:
All options are now specified after commands. That is, if before one would call
after the PR the syntax would be
Pros:
--help. That is, if before, in order to find out about--debug, one would have to callnucypher --helpin addition tonucypher alice --help, now justnucypher alice --helpwill be enough - all the options will be there.A console output emitter is created only once (in
NucypherClickConfig) and propagated to all classes/functions that need it.All
click.echo()andclick.secho()calls are replaced withemitter.echo()calls, so that it can control that output too.Instead of dispatching by keyword arguments in
emitter(), specialized methods are used (banner(),message(),ipc(),echo()).Output trapping in emitters was removed, since it did not seem to be used anywhere.
Added
--log-leveloption from PR Fixes debug docker problem. #1095--verbosityand--quietnow govern console output only (not console observer for logs). The output shown with--quieton should remain the same as before,--verbositycurrently only sets the state of the emitter - actually using it is a matter for another PR. Probably enough to close issue Implement CLI Verbosity Levels and Toggle #1018NOTE: before, when
--quietwas on, logs were written to text file, but not to JSON file. Not sure if it was an omission or a conscious design decision. Now both JSON and text logs are turned on or off together, it can be rolled back.Parsing boolean envvars in
NucypherClickConfigmore rigorously usingstrtobool().Added specific options
--console-logs/--no-console-logs,--file-logs/--no-file-logsand--sentry-logs/--no-sentry-logsto override environment variables without resorting to--debug. Also made option description slightly more detailed.TODO (may be better to leave for another PR):
Add
--no-funfor turning off banners?Instead of specifying color in
echo()andmessage(), use only semantic markup and leave colorizing to the emitter.Go through
emitter.message()andemitter.echo()calls and decide which verbosity levels they should have.To decide (probably for another PR too):
What to do with a few remaining
click.secho()andprint()which lie beyond the scope ofNucypherClickConfigcharacters/control/controllers.pystill creates independent emitters; need to figure out if it is really necessary, and if not, how to propagate the main emitter there