product-os-server 0.0.55

Product OS : Server provides a full functioning advanced server capable of acting as a web server, command and control distributed network, authentication server, crawling server and more. Fully featured with high level of flexibility.
Documentation
//! Logging configuration module
//!
//! Provides functions to configure the global tracing subscriber for the server.

#[cfg(feature = "core")]
use std::prelude::v1::*;

/// Defines logging configuration and returns a subscriber.
///
/// # Arguments
///
/// * `level` - The maximum tracing level to capture
///
/// # Returns
///
/// A configured tracing subscriber ready to be set as the global default.
#[cfg(feature = "core")]
pub fn define_logging(level: tracing::Level) -> impl tracing::Subscriber + Send + Sync {
    tracing_subscriber::fmt()
        .with_max_level(level)
        .finish()
}

/// Sets the global default logger.
///
/// If the global subscriber has already been set (e.g. in tests), the error is
/// logged to stderr but does not prevent the server from starting.
///
/// # Arguments
///
/// * `definition` - The subscriber to set as the global default
///
/// # Returns
///
/// `Ok(())` if the subscriber was set, or an error message if it was already set.
#[cfg(feature = "core")]
pub fn set_global_logger<S>(definition: S) -> Result<(), String>
where
    S: tracing::Subscriber + Send + Sync + 'static
{
    tracing::subscriber::set_global_default(definition)
        .map_err(|e| {
            let msg = alloc::format!("Error setting default subscriber: {}", e);
            eprintln!("{}", msg);
            msg
        })
}