Skip to main content

agentik_sdk/utils/
logging.rs

1use tracing::Level;
2use tracing_subscriber::FmtSubscriber;
3use crate::config::LogLevel;
4
5/// Initialize logging based on the configuration
6pub fn init_logging(log_level: &LogLevel) {
7    let level = match log_level {
8        LogLevel::Error => Level::ERROR,
9        LogLevel::Warn => Level::WARN,
10        LogLevel::Info => Level::INFO, 
11        LogLevel::Debug => Level::DEBUG,
12        LogLevel::Off => return, // Don't initialize logging if disabled
13    };
14
15    let subscriber = FmtSubscriber::builder()
16        .with_max_level(level)
17        .finish();
18
19    let _ = tracing::subscriber::set_global_default(subscriber);
20}
21
22/// Log a request being sent
23pub fn log_request(method: &str, url: &str, body: Option<&str>) {
24    tracing::debug!(
25        method = method,
26        url = url,
27        body = body,
28        "Sending request"
29    );
30}
31
32/// Log a response received
33pub fn log_response(status: u16, body: Option<&str>, request_id: Option<&str>) {
34    tracing::debug!(
35        status = status,
36        body = body,
37        request_id = request_id,
38        "Received response"
39    );
40}