Closed kief closed 2 years ago
I think you maybe just need to add log
to your [dependencies]
in Cargo.toml
, but my rust knowledge is very outdated these days.
When I do that, I get the thread 'main' panicked at 'Could not determine the UTC offset on this system.
error. I've tried Googling that error (and seen there was an issue that was fixed in the current version of simple_logger), and it sounds like something else going on. If it doesn't seem like I'm doing something obviously wrong in using the example code then I guess I can close this issue and dig into it.
That's progress, at least the code compiles now! That second error actually is a known issue in the time
crate, which means unfortunately the default example doesn't work in all contexts.
There should be a bit more detail to the error message - you're likely either running in a multi-threaded environment or on an OS the time
crate does not support. I don't think cargo run --example ...
uses threads by default, so it's likely that you're using an OS that time
doesn't support (sys/local_offset_at/mod.rs in time)
There's a list of workarounds for simple_logger
, depending on how you'd prefer to deal with the issue (mostly taken from https://github.com/borntyping/rust-simple_logger/issues/43).
SimpleLogger::new().with_utc_timestamps().init().unwrap();
)SimpleLogger::new().without_timestamps().init().unwrap();
)time
crates unsafe features: RUSTFLAGS="--cfg unsound_local_offset"
(docs)@kief I thought I recognized that username! Thank you for Infrastructure as Code! 😄
Thanks @jakewan, glad you found it useful! And thanks @borntyping. The error message doesn't give much more detail than your suggestions (MacOS 11.6.1):
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.08s
Running `target/debug/example`
thread 'main' panicked at 'Could not determine the UTC offset on this system. Possible causes are that the time crate does not implement "local_offset_at" on your system, or that you are running in a multi-threaded environment and the time crate is returning "None" from "local_offset_at" to avoid unsafe behaviour. See the time crate's documentation for more information. (https://time-rs.github.io/internal-api/time/index.html#feature-flags): IndeterminateOffset', /Users/kief/.cargo/registry/src/github.com-1ecc6299db9ec823/simple_logger-1.16.0/src/lib.rs:409:85
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I'll find a way to work around it. Clearly not an issue with simple_logger, so,
UTC timestamps are now the default in simple_logger 2.0.0.
Hi,
I'm new to Rust, so may be missing something obvious to more experienced folks.
I created a project following the usage example, but get the error
use of undeclared crate or module 'log'
when I runcargo run
. When I runcargo run --example init
I get the errorno example target named 'init'
.My project has a fail src/main.rs with a copy/paste of the example code:
My Cargo.toml is:
When I run
cargo run
:Is the example is missing something (like a use statement) that a more experienced Rustacian would know to include? I've tried adding use 'log' and including a log crate in my Cargo.toml, but then I get entirely different error messages. I figured I should make sure I'm on the right track with the example and not going down a completely different rabbithole.
The example documentation also suggests running
cargo run --example init
. When I do this, I get thisAgain, this smells like I'm missing a "Rust 101" concept. Clues would be appreciated!