goose_http/log/mod.rs
1//! Logging utilities.
2//!
3//! Centralised logging helpers wrapping `tracing` so components can emit
4//! structured diagnostics without depending on concrete subscribers.
5
6use std::sync::Once;
7
8static INIT: Once = Once::new();
9
10/// Initialise a default tracing subscriber if none has been installed.
11///
12/// Subsequent calls are no-ops, allowing libraries, binaries, and tests to call
13/// this function without worrying about double initialisation panics.
14pub fn init() {
15 INIT.call_once(|| {
16 let _ = tracing_subscriber::fmt()
17 .with_env_filter(
18 tracing_subscriber::EnvFilter::try_from_default_env()
19 .unwrap_or_else(|_| "info".into()),
20 )
21 .with_target(false)
22 .try_init();
23 });
24}
25
26/// Emit an informational log line.
27pub fn info(message: &str) {
28 tracing::info!(message);
29}
30
31/// Emit a warning log line.
32pub fn warn(message: &str) {
33 tracing::warn!(message);
34}
35
36/// Emit an error log line.
37pub fn error(message: &str) {
38 tracing::error!(message);
39}