Silencing outut
Opened this issue · 0 comments
edoardo-c commented
Hello,
It seems I am not alone in trying to silence STDOUT output.
The following is an extract of my code:
if success:
try:
api_connection.start()
result = api_request(*args, **kwargs)
return True, result
except Exception as e:
logger.error(f"API request exception:\n{e}")
return False, None
finally:
api_connection.stop()
else:
logger.error(f"SSH tunnel failed to establish")
When the tunnel fails on api_connection.start()
because it is already running, I get an entry in the logs
[ERROR] API request exception:
...
but I also get an output to STDOUT even though default logging is set to INFO and I also attempted to add a specific log level for sshtunnel
logging.getLogger('sshtunnel').setLevel(logging.WARNING)
logging.getLogger("sshtunnel.SSHTunnelForwarder").setLevel(logging.WARNING)
The output to STDOUT
ERROR | Problem setting SSH Forwarder up: Couldn't open tunnel foo:XX <> bar:XX might be in use or destination not reachable
What can I do for all sshtunnel output to go to logs rather than STDOUT to keep my output informative and clean?
Thanks!
Ed