Skip to content

Commit 124a6fa

Browse files
committed
Move module log_crate to re_export::log
1 parent 8ac1eca commit 124a6fa

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

spdlog/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ mod log_crate_proxy;
263263
mod log_macros;
264264
mod logger;
265265
mod periodic_worker;
266+
pub mod re_export;
266267
mod record;
267268
pub mod sink;
268269
mod source_location;
@@ -682,7 +683,7 @@ pub fn init_env_level_from<K: AsRef<OsStr>>(env_key: K) -> StdResult<bool, EnvLe
682683
/// For more details, please read documentation of [`log::set_logger`] and
683684
/// [`LogCrateProxy`].
684685
#[cfg(feature = "log")]
685-
pub fn init_log_crate_proxy() -> StdResult<(), log_crate::SetLoggerError> {
686+
pub fn init_log_crate_proxy() -> StdResult<(), re_export::log::SetLoggerError> {
686687
log::set_logger(log_crate_proxy())
687688
}
688689

spdlog/src/log_crate_proxy.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
use std::time::SystemTime;
22

3-
/// Re-export some stuff from `log` crate for convenience.
4-
///
5-
/// Users sometimes need these stuff, re-exporting them eliminates the need to
6-
/// explicitly depend on `log` crate in `Cargo.toml`.
7-
///
8-
/// See the documentation of [`LogCrateProxy`].
9-
#[cfg(feature = "log")] // Intentionally redundant, workaround for defects in nested exports of feature
10-
// `doc_auto_cfg`.
11-
pub mod log_crate {
12-
pub use log::{set_max_level, LevelFilter, SetLoggerError};
13-
}
14-
153
use crate::{default_logger, sync::*, Logger, Record};
164

175
/// Log crate proxy.
@@ -25,13 +13,13 @@ use crate::{default_logger, sync::*, Logger, Record};
2513
///
2614
/// Note that the `log` crate uses a different log level filter and by default
2715
/// it rejects all log messages. To make `LogCrateProxy` able to receive log
28-
/// messages from `log` crate, you may need to call [`log_crate::set_max_level`]
29-
/// with [`log_crate::LevelFilter`].
16+
/// messages from `log` crate, you may need to call
17+
/// [`re_export::log::set_max_level`] with [`re_export::log::LevelFilter`].
3018
///
3119
/// ## Examples
3220
///
3321
/// ```
34-
/// use spdlog::log_crate as log;
22+
/// use spdlog::re_export::log;
3523
///
3624
/// # fn main() -> Result<(), log::SetLoggerError> {
3725
/// spdlog::init_log_crate_proxy()?;
@@ -42,6 +30,8 @@ use crate::{default_logger, sync::*, Logger, Record};
4230
///
4331
/// For more and detailed examples, see [./examples] directory.
4432
///
33+
/// [`re_export::log::set_max_level`]: crate::re_export::log::set_max_level
34+
/// [`re_export::log::LevelFilter`]: crate::re_export::log::LevelFilter
4535
/// [./examples]: https://github.com/SpriteOvO/spdlog-rs/tree/main/spdlog/examples
4636
#[derive(Default)]
4737
pub struct LogCrateProxy {

spdlog/src/re_export.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Re-exports items from other crates for convenience.
2+
//!
3+
//! This module selectively re-exports items from other crates that may be used
4+
//! by users. This effectively eliminates the hassle of manually adding
5+
//! dependencies to the user's own `Cargo.toml`.
6+
//!
7+
//! Users can still call items from these crates directly, as long as semver
8+
//! versions of the dependencies are compatible.
9+
10+
/// Items from [`log` crate].
11+
///
12+
/// The `log` crate has its own level filter, and logs produced by `log` crate
13+
/// macros will first be filtered by `log` crate itself (this is not controlled
14+
/// by `spdlog-rs`). When users enable the `log` crate compatibility layer
15+
/// proxy, please make sure that `log` crate's own level filter is configured
16+
/// appropriately so that `spdlog-rs` can receive logs.
17+
///
18+
/// - To enable the `log` crate compatibility layer proxy, call
19+
/// [`spdlog::init_log_crate_proxy`].
20+
///
21+
/// - To configure `log` crate's own level filter, call
22+
/// [`re_export::log::set_max_level`] with [`re_export::log::LevelFilter`].
23+
///
24+
/// [`log` crate]: https://docs.rs/log
25+
/// [`spdlog::init_log_crate_proxy`]: crate::init_log_crate_proxy
26+
/// [`re_export::log::set_max_level`]: crate::re_export::log::set_max_level
27+
/// [`re_export::log::LevelFilter`]: crate::re_export::log::LevelFilter
28+
#[cfg(feature = "log")]
29+
pub mod log {
30+
pub use log::{set_max_level, LevelFilter, SetLoggerError};
31+
}

0 commit comments

Comments
 (0)