Add config options to coarsely disable log/tracing without initialization.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-11-27 18:20:54 +00:00
parent c9362b8605
commit 4f9b1d6dbd
6 changed files with 87 additions and 31 deletions

View File

@@ -912,6 +912,26 @@ pub struct Config {
#[serde(default)]
pub log_to_stderr: bool,
/// Setting to false disables the logging/tracing system at a lower level.
/// In contrast to configuring an empty `log` string where the system is
/// still operating but muted, when this option is false the system was not
/// initialized and is not operating. Changing this option has no effect
/// after startup. This option is intended for developers and expert use
/// only: configuring an empty log string is preferred over using this.
///
/// default: true
#[serde(default = "true_fn")]
pub log_enable: bool,
/// Setting to false disables the logging/tracing system at a lower level
/// similar to `log_enable`. In this case the system is configured normally,
/// but not registered as the global handler in the final steps. This option
/// is for developers and expert use only.
///
/// default: true
#[serde(default = "true_fn")]
pub log_global_default: bool,
/// OpenID token expiration/TTL in seconds.
///
/// These are the OpenID tokens that are primarily used for Matrix account

View File

@@ -8,23 +8,31 @@ pub mod fmt_span;
mod reload;
mod suppress;
pub use capture::Capture;
pub use console::{ConsoleFormat, ConsoleWriter, is_systemd_mode};
pub use reload::{LogLevelReloadHandles, ReloadHandle};
pub use suppress::Suppress;
pub use tracing::Level;
use std::sync::Arc;
pub use tracing::{Level, subscriber::Subscriber};
pub use tracing_core::{Event, Metadata};
pub use tracing_subscriber::EnvFilter;
pub use self::{
capture::Capture,
console::{ConsoleFormat, ConsoleWriter, is_systemd_mode},
reload::{LogLevelReloadHandles, ReloadHandle},
suppress::Suppress,
};
/// Logging subsystem. This is a singleton member of super::Server which holds
/// all logging and tracing related state rather than shoving it all in
/// super::Server directly.
pub struct Log {
pub struct Logging {
/// Subscriber assigned to globals and defaults; may also be NoSubscriber.
pub subscriber: Arc<dyn Subscriber + Send + Sync>,
/// General log level reload handles.
pub reload: LogLevelReloadHandles,
/// Tracing capture state for ephemeral/oneshot uses.
pub capture: std::sync::Arc<capture::State>,
pub capture: Arc<capture::State>,
}
// Wraps for logging macros. Use these macros rather than extern tracing:: or

View File

@@ -9,7 +9,7 @@ use std::{
use ruma::OwnedServerName;
use tokio::{runtime, sync::broadcast};
use crate::{Err, Result, config, config::Config, log::Log, metrics::Metrics};
use crate::{Err, Result, config, config::Config, log::Logging, metrics::Metrics};
/// Server runtime state; public portion
pub struct Server {
@@ -41,7 +41,7 @@ pub struct Server {
pub signal: broadcast::Sender<&'static str>,
/// Logging subsystem state
pub log: Log,
pub log: Logging,
/// Metrics subsystem state
pub metrics: Metrics,
@@ -49,7 +49,7 @@ pub struct Server {
impl Server {
#[must_use]
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Log) -> Self {
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Logging) -> Self {
Self {
name: config.server_name.clone(),
config: config::Manager::new(config),