diff --git a/nucypher/blockchain/eth/interfaces.py b/nucypher/blockchain/eth/interfaces.py index cf1cef928..0d5c8e6ee 100644 --- a/nucypher/blockchain/eth/interfaces.py +++ b/nucypher/blockchain/eth/interfaces.py @@ -158,7 +158,6 @@ class BlockchainInterface: @staticmethod def __default_on_broadcast(tx: PendingTx): - # TODO review use of emitter - #3482 emitter = StdoutEmitter() max_cost, max_price_gwei, tx_type = get_tx_cost_data(tx.params) emitter.message( @@ -623,7 +622,6 @@ class BlockchainInterface: # # Broadcast # - # TODO review use of emitter - #3482 emitter.message( f"Broadcasting {transaction_name} {tx_type} Transaction ({max_cost} @ {max_price_gwei} gwei)", color="yellow", diff --git a/nucypher/utilities/emitters.py b/nucypher/utilities/emitters.py index 71bd59c36..98c96b016 100644 --- a/nucypher/utilities/emitters.py +++ b/nucypher/utilities/emitters.py @@ -1,33 +1,16 @@ -import os -from functools import partial -from typing import Callable - import click from nucypher.utilities.logging import Logger -def null_stream(): - return open(os.devnull, 'w') - - class StdoutEmitter: - class MethodNotFound(BaseException): - """Cannot find interface method to handle request""" - - transport_serializer = str default_color = 'white' - # sys.stdout.write() TODO: doesn't work well with click_runner's output capture - default_sink_callable = partial(print, flush=True) - def __init__(self, - sink: Callable = None, verbosity: int = 1): self.name = self.__class__.__name__.lower() - self.sink = sink or self.default_sink_callable self.verbosity = verbosity self.log = Logger(self.name) @@ -41,7 +24,12 @@ class StdoutEmitter: bold: bool = False, verbosity: int = 1): self.echo(message, color=color or self.default_color, bold=bold, verbosity=verbosity) - self.log.debug(message) + # these are application messages that are desired to be + # printed to stdout (with or w/o console logging); send to logger + if verbosity > 1: + self.log.debug(message) + else: + self.log.info(message) def echo(self, message: str = None, @@ -49,21 +37,18 @@ class StdoutEmitter: bold: bool = False, nl: bool = True, verbosity: int = 0): + # these are user interactions; don't send to logger if verbosity <= self.verbosity: click.secho(message=message, fg=color or self.default_color, bold=bold, nl=nl) def banner(self, banner): + # these are purely for banners; don't send to logger if self.verbosity >= 1: click.echo(banner) def error(self, e): + e_str = str(e) if self.verbosity >= 1: - e_str = str(e) click.echo(message=e_str, color="red") - self.log.info(e_str) - - def get_stream(self, verbosity: int = 0): - if verbosity <= self.verbosity: - return click.get_text_stream('stdout') - else: - return null_stream() + # some kind of error; send to logger + self.log.error(e_str)