Skip to content

Commit

Permalink
ATOR-295 - Fix log level
Browse files Browse the repository at this point in the history
  • Loading branch information
yumirkov committed May 31, 2024
1 parent bef939a commit b0be6f1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions docs/source/man_sbws.ini.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ logging
If logging to file, how many backups to keep. If zero or max bytes is zero,
never rotate the log file. (Default: 50)
level = {debug, info, warning, error, critical}
Level to log at. (Default: debug)
Level to log at. (Default: info)
to_file_level = {debug, info, warning, error, critical}
Level to log at when using files. (Default: debug)
Level to log at when using files. (Default: info)
to_stdout_level = {debug, info, warning, error, critical}
Level to log at when using stdout. (Default: debug)
Level to log at when using stdout. (Default: info)
to_syslog_level = {debug, info, warning, error, critical}
Level to log at when using syslog. (Default: debug)
Level to log at when using syslog. (Default: info)
format = STR
Format string to use when logging.
(Default: %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s)
Expand Down
8 changes: 4 additions & 4 deletions sbws/config.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ to_file_max_bytes = 10485760
to_file_num_backups = 50
# Level to log at. Debug, info, warning, error, critical.
# `level` must be set to the lower of all the handler levels.
level = debug
to_file_level = debug
to_stdout_level = debug
to_syslog_level = debug
level = info
to_file_level = info
to_stdout_level = info
to_syslog_level = info
# Format string to use when logging
format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> (%(threadName)s) %(message)s
to_stdout_format = ${format}
Expand Down
22 changes: 11 additions & 11 deletions sbws/core/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def timed_recv_from_server(session, dest, byte_range):
# does not catch all the ssl exceptions and urllib3 doesn't seem to have
# a base exception class.
except Exception as e:
log.debug(e)
log.error(e)
return False, e
end_time = time.monotonic()
return True, end_time - start_time
Expand Down Expand Up @@ -161,7 +161,7 @@ def measure_rtt_to_server(session, conf, dest, content_length):
success, data = timed_recv_from_server(session, dest, random_range)
if not success:
# data is an exception
log.debug(
log.warning(
"While measuring the RTT to %s we hit an exception "
"(does the webserver support Range requests?): %s",
dest.url,
Expand Down Expand Up @@ -195,7 +195,7 @@ def measure_bandwidth_to_server(session, conf, dest, content_length):
success, data = timed_recv_from_server(session, dest, random_range)
if not success:
# data is an exception
log.debug(
log.warning(
"While measuring the bandwidth to %s we hit an "
"exception (does the webserver support Range "
"requests?): %s",
Expand Down Expand Up @@ -272,11 +272,11 @@ def upload_data(session, conf, dest, cont, circ_id):
msg = "Could not connect to {} over circ {} {}: {}".format(
dest.url, circ_id, stem_utils.circuit_str(cont, circ_id), e
)
log.debug("%s: %s", msg, e)
log.error("%s: %s", msg, e)
return None, msg
except Exception as e:
dest.add_failure()
log.debug(e)
log.error(e)
return None, e
finally:
log.debug("Finished uploading data.")
Expand All @@ -287,7 +287,7 @@ def upload_data(session, conf, dest, cont, circ_id):
"When sending HTTP POST to {}, we expected HTTP code {} "
"not {}".format(dest.url, requests.codes.ok, response.status_code)
)
log.debug(msg)
log.error(msg)
return None, msg

dest.add_success()
Expand Down Expand Up @@ -368,7 +368,7 @@ def _pick_ideal_second_hop(relay, rl, relay_as_entry, candidates):

def error_no_helper(relay, dest, our_nick=""):
reason = "Unable to select a second relay"
log.debug(
log.error(
reason + " to help measure %s (%s)", relay.fingerprint, relay.nickname
)
return [
Expand Down Expand Up @@ -401,7 +401,7 @@ def create_path_relay(relay, dest, rl, relay_as_entry, candidates):


def error_no_circuit(circ_fps, nicknames, reason, relay, dest, our_nick):
log.debug(
log.error(
"Could not build circuit with path %s (%s): %s ",
circ_fps,
nicknames,
Expand Down Expand Up @@ -694,7 +694,7 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
dest, circ_id, s, cb.controller, dest._max_dl
)
if not is_usable:
log.debug(
log.error(
"Failed to connect to %s to measure %s (%s) via circuit "
"%s (%s). Exit policy: %s. Reason: %s.",
dest.url,
Expand All @@ -716,7 +716,7 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
s, conf, dest, usable_data["content_length"]
)
if rtts is None:
log.debug(
log.warning(
"Unable to measure RTT for %s (%s) to %s via circuit "
"%s (%s): %s",
relay.fingerprint,
Expand Down Expand Up @@ -790,7 +790,7 @@ def dispatch_worker_thread(*a, **kw):
# In case the arguments or the method change, catch the possible exceptions
# but ignore here that there are not destinations.
except (IndexError, TypeError):
log.debug("Wrong argument or attribute.")
log.error("Wrong argument or attribute.")
functional_destinations = True
if not functional_destinations or settings.end_event.is_set():
return None
Expand Down
2 changes: 1 addition & 1 deletion sbws/lib/circuitbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def close_circuit(self, circ_id):
self.controller.close_circuit(circ_id)
# SocketClosed will be raised when stopping sbws
except (InvalidArguments, InvalidRequest, SocketClosed) as e:
log.debug(e)
log.error(e)
self.built_circuits.discard(circ_id)

def _build_circuit_impl(self, path):
Expand Down
2 changes: 1 addition & 1 deletion sbws/lib/resultdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def handle_result(self, result):
fp = result.fingerprint
nick = result.nickname
if isinstance(result, ResultError) and settings.end_event.is_set():
log.debug(
log.error(
"Ignoring %s for %s %s because we are shutting down",
type(result).__name__,
nick,
Expand Down
2 changes: 1 addition & 1 deletion sbws/lib/v3bwfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ def read_number_consensus_relays(consensus_path):
try:
num = len(list(parse_file(consensus_path)))
except (FileNotFoundError, AttributeError):
log.info(
log.warning(
"It is not possible to obtain statistics about the "
"percentage of measured relays because the cached "
"consensus file is not found."
Expand Down
2 changes: 1 addition & 1 deletion sbws/util/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def is_low_space(conf):
disk_required_mb = sbws_required_disk_space(conf)
disk_avail_mb = df(conf.getpath("paths", "sbws_home"))
if disk_avail_mb < disk_required_mb:
log.warn(
log.warning(
"The space left on the device (%s MiB) is less than "
"the minimum recommended to run sbws (%s MiB)."
"Run sbws cleanup to delete old sbws generated files.",
Expand Down
14 changes: 7 additions & 7 deletions sbws/util/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def closure_stream_event_listener(st):
InvalidRequest,
OperationFailed,
) as e:
log.debug(
log.error(
"Error attaching stream %s to circ %s: %s",
st.id,
circ_id,
Expand Down Expand Up @@ -129,7 +129,7 @@ def remove_event_listener(controller, func):
controller.remove_event_listener(func)
except SocketClosed as e:
if not settings.end_event.is_set():
log.debug(e)
log.error(e)
else:
log.exception(e)
except ProtocolError as e:
Expand Down Expand Up @@ -181,7 +181,7 @@ def _init_controller_socket(socket):
# todo - extract password to config
c.authenticate(password="password")
except (IncorrectSocketType, SocketError):
log.debug("Error initting controller socket: socket error.")
log.error("Error initting controller socket: socket error.")
return None
except Exception as e:
log.exception("Error initting controller socket: %s", e)
Expand Down Expand Up @@ -272,7 +272,7 @@ def set_torrc_options_can_fail(controller):
try:
controller.set_conf(k, v)
except (InvalidArguments, InvalidRequest) as error:
log.debug(
log.error(
"Ignoring option not supported by this Tor version. %s", error
)
except ControllerError as e:
Expand Down Expand Up @@ -347,11 +347,11 @@ def get_socks_info(controller):
return socks_ports[0]
except SocketClosed as e:
if not settings.end_event.is_set():
log.debug(e)
log.error(e)
# This might need to return the exception if this happen in other cases
# than when stopping the scanner.
except ControllerError as e:
log.debug(e)
log.error(e)


def only_relays_with_bandwidth(relays, min_bw=None, max_bw=None):
Expand Down Expand Up @@ -385,7 +385,7 @@ def circuit_str(controller, circ_id):
return None
# exceptions raised when stopping the scanner
except (ControllerError, SocketClosed, socks.GeneralProxyError) as e:
log.debug(e)
log.error(e)
return None
return (
"["
Expand Down

0 comments on commit b0be6f1

Please sign in to comment.