devela/sys/log/
namespace.rs

1// devela::sys::log::namespace
2
3use super::{LogLevelFilter, Logger, LoggerSetError};
4#[cfg(feature = "std")]
5use ::log::set_boxed_logger;
6#[cfg(all(not(feature = "safe_sys"), feature = "unsafe_thread"))]
7use ::log::set_logger_racy;
8use ::log::{logger, max_level, set_logger, set_max_level, STATIC_MAX_LEVEL};
9
10#[doc = crate::TAG_NAMESPACE!()]
11/// Log-related operations.
12///
13/// It is a namespace for the `log` crate standalone functions.
14#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "dep_log")))]
15pub struct Log;
16
17impl Log {
18    /* log crate */
19
20    /// The statically resolved maximum log level.
21    ///
22    /// Returns [`STATIC_MAX_LEVEL`].
23    pub const MAX_LEVEL: LogLevelFilter = STATIC_MAX_LEVEL;
24
25    /// Returns the current maximum log level.
26    ///
27    /// See `::log::`[`max_level`].
28    #[rustfmt::skip]
29    pub fn max_level() -> LogLevelFilter { max_level() }
30
31    /// Sets the global maximum log level.
32    ///
33    /// See `::log::`[`set_max_level`].
34    #[rustfmt::skip]
35    pub fn set_max_level(level: LogLevelFilter) { set_max_level(level) }
36
37    /// Returns a reference to the current global logger.
38    ///
39    /// See `::log::`[`logger`].
40    pub fn logger() -> &'static dyn Logger {
41        logger()
42    }
43
44    /// Sets the global logger to a `&'static Log`.
45    ///
46    /// See `::log::`[`set_logger`].
47    #[cfg(target_has_atomic = "ptr")]
48    #[cfg_attr(feature = "nightly_doc", doc(cfg(target_has_atomic = "ptr")))]
49    pub fn set_logger(logger: &'static dyn Logger) -> Result<(), LoggerSetError> {
50        set_logger(logger)
51    }
52
53    /// Sets the global logger to a `Box<Log>`.
54    ///
55    /// See `::log::`[`set_boxed_logger`].
56    #[cfg(all(feature = "std", target_has_atomic = "ptr"))]
57    #[cfg_attr(feature = "nightly_doc", doc(cfg(all(feature = "std", target_has_atomic = "ptr"))))]
58    pub fn set_boxed_logger(logger: Box<dyn Logger>) -> Result<(), LoggerSetError> {
59        set_boxed_logger(logger)
60    }
61
62    /// A thread-unsafe version of set_logger.
63    ///
64    /// See `::log::`[`set_logger_racy`].
65    ///
66    /// # Safety
67    /// See the related documentation in `set_logger_racy`.
68    #[cfg(all(not(feature = "safe_sys"), feature = "unsafe_thread"))]
69    #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "unsafe_thread")))]
70    pub unsafe fn set_logger_racy(logger: &'static dyn Logger) -> Result<(), LoggerSetError> {
71        // SAFETY: caller must ensure safety
72        unsafe { set_logger_racy(logger) }
73    }
74
75    /* */
76}