Skip to content

Commit

Permalink
chore(apple): initiate logging subscriber as early as possible (#4143)
Browse files Browse the repository at this point in the history
Also, return error with tracing subscriber initialization
  • Loading branch information
conectado committed Mar 14, 2024
1 parent be22e99 commit 05e5ca6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions rust/connlib/clients/apple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::{
time::Duration,
};
use tokio::runtime::Runtime;
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
use tracing_subscriber::{prelude::*, util::TryInitError};

/// The Apple client implements reconnect logic in the upper layer using OS provided
/// APIs to detect network connectivity changes. The reconnect timeout here only
Expand Down Expand Up @@ -168,18 +168,18 @@ impl Callbacks for CallbackHandler {
}
}

fn init_logging(log_dir: PathBuf, log_filter: String) -> file_logger::Handle {
fn init_logging(log_dir: PathBuf, log_filter: String) -> Result<file_logger::Handle, TryInitError> {
let (file_layer, handle) = file_logger::layer(&log_dir);

let _ = tracing_subscriber::registry()
tracing_subscriber::registry()
.with(
tracing_oslog::OsLogger::new("dev.firezone.firezone", "connlib")
.with_filter(EnvFilter::new(log_filter.clone())),
)
.with(file_layer.with_filter(EnvFilter::new(log_filter)))
.try_init();
.try_init()?;

handle
Ok(handle)
}

impl WrappedSession {
Expand All @@ -196,6 +196,7 @@ impl WrappedSession {
log_filter: String,
callback_handler: ffi::CallbackHandler,
) -> Result<Self, String> {
let handle = init_logging(log_dir.into(), log_filter).map_err(|e| e.to_string())?;
let secret = SecretString::from(token);

let (private_key, public_key) = keypair();
Expand All @@ -219,7 +220,7 @@ impl WrappedSession {
os_version_override,
CallbackHandler {
inner: Arc::new(callback_handler),
handle: init_logging(log_dir.into(), log_filter),
handle,
},
Some(MAX_PARTITION_TIME),
runtime.handle().clone(),
Expand Down

0 comments on commit 05e5ca6

Please sign in to comment.