Commit 3dfe8e65 authored by Chelsea Holland Komlo's avatar Chelsea Holland Komlo
Browse files

add minimal rust module for logging to tor's logger

Allows an optional no-op for testing purposes
parent 719db28f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -52,6 +52,13 @@

#define raw_assert(x) assert(x) // assert OK

/** Defining compile-time constants for Tor log levels (used by the Rust
 * log wrapper at src/rust/tor_log) */
const int _LOG_WARN = LOG_WARN;
const int _LOG_NOTICE = LOG_NOTICE;
const log_domain_mask_t _LD_GENERAL = LD_GENERAL;
const log_domain_mask_t _LD_NET = LD_NET;

/** Information for a single logfile; only used in log.c */
typedef struct logfile_t {
  struct logfile_t *next; /**< Next logfile_t in the linked list. */
+10 −0
Original line number Diff line number Diff line
@@ -31,6 +31,16 @@
 * "maximum severity" read "most severe" and "numerically *lowest* severity".
 */

/** This defines log levels that are linked in the Rust log module, rather
 * than re-defining these in both Rust and C.
 *
 * C_RUST_COUPLED src/rust/tor_log LogSeverity, LogDomain
 */
extern const int _LOG_WARN;
extern const int _LOG_NOTICE;
extern const log_domain_mask_t _LD_NET;
extern const log_domain_mask_t _LD_GENERAL;

/** Debug-level severity: for hyper-verbose messages of no interest to
 * anybody but developers. */
#define LOG_DEBUG   7
+2 −6
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ void evdns_shutdown(int);
#ifdef HAVE_RUST
// helper function defined in Rust to output a log message indicating if tor is
// running with Rust enabled. See src/rust/tor_util
char *rust_welcome_string(void);
void rust_welcome_string(void);
#endif

/********* PROTOTYPES **********/
@@ -3283,11 +3283,7 @@ tor_init(int argc, char *argv[])
  }

#ifdef HAVE_RUST
  char *rust_str = rust_welcome_string();
  if (rust_str != NULL && strlen(rust_str) > 0) {
    log_notice(LD_GENERAL, "%s", rust_str);
  }
  tor_free(rust_str);
  rust_welcome_string();
#endif /* defined(HAVE_RUST) */

  if (network_init()<0) {
+10 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ version = "0.0.1"
dependencies = [
 "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
 "tor_allocate 0.0.1",
 "tor_log 0.1.0",
]

[[package]]
@@ -26,6 +27,7 @@ dependencies = [
 "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
 "smartlist 0.0.1",
 "tor_allocate 0.0.1",
 "tor_log 0.1.0",
 "tor_util 0.0.1",
]

@@ -43,6 +45,14 @@ dependencies = [
 "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tor_log"
version = "0.1.0"
dependencies = [
 "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
 "tor_allocate 0.0.1",
]

[[package]]
name = "tor_rust"
version = "0.1.0"
+2 −1
Original line number Diff line number Diff line
[workspace]
members = ["tor_util", "protover", "smartlist", "external", "tor_allocate", "tor_rust"]
members = ["tor_util", "protover", "smartlist", "external", "tor_allocate",
"tor_rust", "tor_log"]

[profile.release]
debug = true
Loading