mirror of
https://github.com/BurntSushi/jiff.git
synced 2025-12-23 08:47:45 +00:00
While in #370 my tests indicated that the slowest tzdb init was still under ~33ms, right after it merged to master, I saw a spike to 300ms. 300ms is... probably still tolerable, but just barely I think. So this PR bumps up our threshold to 500ms. We also enable logging to hopefully get a better sense of where time is being spent. Finally, we just to improve things by skipping the `right` and `posix` directories in typicaly `/usr/share/zoneinfo` installations. Jiff doesn't use them and they tend to be confusing outputs of `TimeZoneDatabase::available()`. If users actually need those directories, they can do `TZDIR=/usr/share/zoneinfo/posix`. Ref #366
90 lines
2.7 KiB
Rust
90 lines
2.7 KiB
Rust
// See: https://github.com/rust-lang/rust/pull/121364
|
|
#![allow(unknown_lints, ambiguous_negative_literals)]
|
|
|
|
mod init;
|
|
mod procmacro;
|
|
mod tc39_262;
|
|
|
|
/// The simplest possible logger that logs to stderr.
|
|
///
|
|
/// This logger does no filtering. Instead, it relies on the `log` crates
|
|
/// filtering via its global max_level setting.
|
|
///
|
|
/// This provides a super simple logger that works with the `log` crate.
|
|
/// We don't need anything fancy; just basic log levels and the ability to
|
|
/// print to stderr. We therefore avoid bringing in extra dependencies just
|
|
/// for this functionality.
|
|
#[cfg(all(test))]
|
|
#[derive(Debug)]
|
|
pub(crate) struct Logger(());
|
|
|
|
#[cfg(all(test, feature = "std", feature = "logging"))]
|
|
const LOGGER: &'static Logger = &Logger(());
|
|
|
|
#[cfg(all(test))]
|
|
impl Logger {
|
|
/// Create a new logger that logs to stderr and initialize it as the
|
|
/// global logger. If there was a problem setting the logger, then an
|
|
/// error is returned.
|
|
pub(crate) fn init() -> Result<(), log::SetLoggerError> {
|
|
#[cfg(all(feature = "std", feature = "logging"))]
|
|
{
|
|
log::set_logger(LOGGER)?;
|
|
log::set_max_level(log::LevelFilter::Trace);
|
|
Ok(())
|
|
}
|
|
#[cfg(not(all(feature = "std", feature = "logging")))]
|
|
{
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(all(test, feature = "std", feature = "logging"))]
|
|
impl log::Log for Logger {
|
|
fn enabled(&self, _: &log::Metadata<'_>) -> bool {
|
|
// We set the log level via log::set_max_level, so we don't need to
|
|
// implement filtering here.
|
|
true
|
|
}
|
|
|
|
fn log(&self, record: &log::Record<'_>) {
|
|
let now = jiff::Timestamp::now();
|
|
match (record.file(), record.line()) {
|
|
(Some(file), Some(line)) => {
|
|
std::eprintln!(
|
|
"{}|{}|{}|{}:{}: {}",
|
|
now,
|
|
record.level(),
|
|
record.target(),
|
|
file,
|
|
line,
|
|
record.args()
|
|
);
|
|
}
|
|
(Some(file), None) => {
|
|
std::eprintln!(
|
|
"{}|{}|{}|{}: {}",
|
|
now,
|
|
record.level(),
|
|
record.target(),
|
|
file,
|
|
record.args()
|
|
);
|
|
}
|
|
_ => {
|
|
std::eprintln!(
|
|
"{}|{}|{}: {}",
|
|
now,
|
|
record.level(),
|
|
record.target(),
|
|
record.args()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn flush(&self) {
|
|
// We use eprintln! which is flushed on every call.
|
|
}
|
|
}
|