Browse Source

Improved logging

Removed some logging, changed some logging from warning to debug,
and set the logging so that other threads will only log messages
of level warning or higher.
Steven Engler 4 years ago
parent
commit
6621019596

+ 1 - 0
src/core/mainloop/connection.c

@@ -5040,6 +5040,7 @@ connection_process_inbuf(connection_t *conn, int package_partial)
   switch (conn->type) {
     case CONN_TYPE_OR:
       tor_assert(0);
+      return -1;
       //return connection_or_process_inbuf(TO_OR_CONN(conn));
     case CONN_TYPE_EXT_OR:
       return connection_ext_or_process_inbuf(TO_OR_CONN(conn));

+ 2 - 1
src/core/or/circuitlist.c

@@ -2672,7 +2672,8 @@ circuits_handle_oom(size_t current_allocation)
   int n_dirconns_killed=0;
   uint32_t now_ts;
   log_notice(LD_GENERAL, "We're low on memory (cell queues total alloc:"
-             " %"TOR_PRIuSZ" buffer total alloc: %" TOR_PRIuSZ ","
+             //" %"TOR_PRIuSZ" buffer total alloc: %" TOR_PRIuSZ ","
+             " %"TOR_PRIuSZ" buffer total alloc: <unknown>,"
              " tor compress total alloc: %" TOR_PRIuSZ
              " (zlib: %" TOR_PRIuSZ ", zstd: %" TOR_PRIuSZ ","
              " lzma: %" TOR_PRIuSZ "),"

+ 1 - 1
src/core/or/connection_or.c

@@ -504,7 +504,7 @@ connection_or_process_event(event_label_t label, event_data_t data,
     or_conn->tls_peer_cert = handshake_data->tls_peer_cert;
 
     tor_assert(or_conn->base_.state == OR_CONN_STATE_TLS_HANDSHAKING);
-    log_warn(LD_OR, "OR conn recieved link handshaking event: %s", or_conn->is_outgoing?"outgoing":"incoming");
+    log_debug(LD_OR, "OR conn recieved link handshaking event: %s", or_conn->is_outgoing?"outgoing":"incoming");
     if (or_conn->is_outgoing) {
       tor_assert(connection_or_launch_v3_or_handshake(or_conn) == 0);
     } else {

+ 9 - 24
src/core/or/safe_connection.c

@@ -832,9 +832,8 @@ safe_or_connection_update_state(safe_or_connection_t *safe_or_conn,
     break;
   }
 
-  log_warn(LD_OR, "Safe OR conn changed from state %d to state %d",
+  log_debug(LD_OR, "Safe OR conn changed from state %d to state %d",
             safe_or_conn->state, new_state);
-  // TODO: change back to debug ^^
   safe_or_conn->state = new_state;
 
   return E_SUCCESS;
@@ -1005,9 +1004,6 @@ safe_or_connection_read_encrypted(safe_or_connection_t *safe_or_conn,
     safe_or_connection_max_bytes_can_read(safe_or_conn, use_conn_buckets);
   // we may read slightly more than this due to pending TLS bytes
 
-  log_warn(LD_NET, "suggested_bytes_to_read: %zu", suggested_bytes_to_read);
-  // TODO: remove this ^^
-
   if (suggested_bytes_to_read == 0) {
     log_debug(LD_NET, "Read callback running, but not supposed to read bytes.");
     return E_SUCCESS;
@@ -1061,9 +1057,8 @@ safe_or_connection_read_encrypted(safe_or_connection_t *safe_or_conn,
   size_t tls_bytes_written = 0;
   tor_tls_get_n_raw_bytes(safe_or_conn->tls, &tls_bytes_read,
                           &tls_bytes_written);
-  log_warn(LD_NET, "After TLS read of %zu: %zu read, %zu written",
+  log_debug(LD_NET, "After TLS read of %zu: %zu read, %zu written",
             bytes_read, tls_bytes_read, tls_bytes_written);
-  // TODO: change this back to debug ^^
 
   safe_or_connection_decrement_buckets(safe_or_conn, tls_bytes_read,
                                        tls_bytes_written, use_conn_buckets);
@@ -1085,9 +1080,6 @@ safe_or_connection_write_encrypted(safe_or_connection_t *safe_or_conn,
   size_t max_bytes_to_write = \
     safe_or_connection_max_bytes_can_write(safe_or_conn, use_conn_buckets);
 
-  log_warn(LD_NET, "max_bytes_to_write: %zu", max_bytes_to_write);
-  // TODO: remove this ^^
-
   if (max_bytes_to_write == 0) {
     log_debug(LD_NET, "Write callback running, but not supposed to write bytes.");
     return E_SUCCESS;
@@ -1112,14 +1104,10 @@ safe_or_connection_write_encrypted(safe_or_connection_t *safe_or_conn,
   case TOR_TLS_WANTWRITE:
     // we need to wait for the socket to become writable
     // again, then do another write
-    log_warn(LD_NET, "Wants write");
-    // TODO: remove this ^^
     break;
   case TOR_TLS_WANTREAD:
     // we need to wait for the socket to become readable
     // before we can do another write
-    log_warn(LD_NET, "Wants read");
-    // TODO: remove this ^^
     socket_rw_state_set(&safe_or_conn->tls_read_wanted, true,
                         TO_SAFE_CONN(safe_or_conn));
     socket_rw_state_set(&safe_or_conn->tor_write_wanted, false,
@@ -1157,9 +1145,8 @@ safe_or_connection_write_encrypted(safe_or_connection_t *safe_or_conn,
   size_t tls_bytes_written = 0;
   tor_tls_get_n_raw_bytes(safe_or_conn->tls, &tls_bytes_read,
                           &tls_bytes_written);
-  log_warn(LD_NET, "After TLS write of %zu: %zu read, %zu written",
+  log_debug(LD_NET, "After TLS write of %zu: %zu read, %zu written",
             bytes_written, tls_bytes_read, tls_bytes_written);
-  // TODO: change this back to debug ^^
 
   safe_or_connection_decrement_buckets(safe_or_conn, tls_bytes_read,
                                        tls_bytes_written, use_conn_buckets);
@@ -1266,10 +1253,9 @@ safe_or_connection_read_cb(safe_connection_t *safe_conn)
   tor_assert(safe_conn != NULL);
   safe_or_connection_t *safe_or_conn = TO_SAFE_OR_CONN(safe_conn);
 
-  log_warn(LD_OR, "OR Connection Read  (state=%d, obj=%p, %s)!!!!",
-           safe_or_conn->state, safe_or_conn,
-           safe_or_conn->is_outgoing?"outgoing":"incoming");
-  // TODO: remove this ^^
+  log_debug(LD_OR, "OR connection read cb  (state=%d, obj=%p, %s)",
+            safe_or_conn->state, safe_or_conn,
+            safe_or_conn->is_outgoing?"outgoing":"incoming");
 
   //if (safe_or_conn->tls_write_waiting_on_socket_readable) {
   //  // since the socket is now readable, we can re-enable TLS write again
@@ -1362,10 +1348,9 @@ safe_or_connection_write_cb(safe_connection_t *safe_conn)
   tor_assert(safe_conn != NULL);
   safe_or_connection_t *safe_or_conn = TO_SAFE_OR_CONN(safe_conn);
 
-  log_warn(LD_OR, "OR Connection Write (state=%d, obj=%p, %s)!!!!",
-           safe_or_conn->state, safe_or_conn,
-           safe_or_conn->is_outgoing?"outgoing":"incoming");
-  // TODO: remove this ^^
+  log_debug(LD_OR, "OR connection write cb (state=%d, obj=%p, %s)",
+            safe_or_conn->state, safe_or_conn,
+            safe_or_conn->is_outgoing?"outgoing":"incoming");
 
   switch (safe_or_conn->state) {
   case SAFE_OR_CONN_STATE_UNINITIALIZED:

+ 5 - 0
src/lib/log/log.c

@@ -574,6 +574,11 @@ MOCK_IMPL(STATIC void,
 logv,(int severity, log_domain_mask_t domain, const char *funcname,
      const char *suffix, const char *format, va_list ap))
 {
+  if (!in_main_thread() && severity < LOG_WARN) {
+    // don't log unimportant messages from other threads
+    return;
+  }
+
   char buf[10240];
   size_t msg_len = 0;
   int formatted = 0;