[tor-bugs] #23881 [Core Tor/Tor]: Implement a way to utilise tor's logging system from Rust code
Tor Bug Tracker & Wiki
blackhole at torproject.org
Mon Dec 18 04:44:44 UTC 2017
#23881: Implement a way to utilise tor's logging system from Rust code
------------------------------+------------------------------------
Reporter: isis | Owner: chelseakomlo
Type: enhancement | Status: needs_revision
Priority: High | Milestone: Tor: 0.3.3.x-final
Component: Core Tor/Tor | Version:
Severity: Normal | Resolution:
Keywords: rust, rust-pilot | Actual Points:
Parent ID: | Points: 3
Reviewer: | Sponsor:
------------------------------+------------------------------------
Comment (by chelseakomlo):
See fixes from Manish's review on the same branch:
`https://oniongit.eu/network/tor/merge_requests/7`
A couple thoughts:
1. Testing
I wasn't able to test the inline logging function, as I wasn't sure the
best way how to. I think I could properly test this with a global variable
that was only defined for unit tests (such as a Cursor<Vec>, and "log" to
it in the no-op implementation. However, I ran into issues due to the
limitation of creating non-struct static types in stable Rust.
For example, for the following declaration:
`pub static mut log_cursor: Cursor<Vec<String>> =
Cursor::new(Vec::new());`
I received this error:
`calls in statics are limited to struct and enum constructors`
And for this declaration:
{{{
struct LastLogged {
function: Option<String>
message: Option<String>
}
}}}
I received this error:
`destructors in statics are an unstable feature`
Maybe we just need to wait for this feature to land in stable, but it
would be nice to have the flexibility for functions that are inherently
hard to test, without having to change the code itself.
2. Feature flags for `cargo test`
I am unable to run `cargo test` with a specific flag. For example, I
wanted to be able to run `cargo test --feature "testing"`, but this flag
is not applied to other modules as well (i.e, running tests in protover
will not result in tor_log being compiled with the "testing" flag). I'm
able to run `cargo test --all-features` but being able to turn on features
at a fine-grained level for tests would be nice.
3. Binding compile-time constants to log level macros
Nick- as for the declaration of log levels in src/common/torlog.h, if we
can refactor these into compile-time constants (instead of macros) that
would remove the need to declare _constant for each. Let me know what you
think, I can help do this refactor.
For example, instead of binding _LD_NET to LD_NET, we could declare LD_NET
as a constant directly.
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/23881#comment:14>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list