diff --git a/rust/connlib/clients/apple/src/lib.rs b/rust/connlib/clients/apple/src/lib.rs index f5a5a2e44..4a1e48a5f 100644 --- a/rust/connlib/clients/apple/src/lib.rs +++ b/rust/connlib/clients/apple/src/lib.rs @@ -77,6 +77,9 @@ mod ffi { #[swift_bridge(swift_name = "setDisabledResources", return_with = err_to_string)] fn set_disabled_resources(&mut self, disabled_resources: String) -> Result<(), String>; + + #[swift_bridge(swift_name = "setLogDirectives", return_with = err_to_string)] + fn set_log_directives(&mut self, directives: String) -> Result<(), String>; } extern "Swift" { @@ -174,6 +177,11 @@ impl Callbacks for CallbackHandler { } } +static LOGGER_STATE: OnceLock<( + firezone_logging::file::Handle, + firezone_logging::FilterReloadHandle, +)> = OnceLock::new(); + /// Initialises a global logger with the specified log filter. /// /// A global logger can only be set once, hence this function uses `static` state to check whether a logger has already been set. @@ -181,11 +189,6 @@ impl Callbacks for CallbackHandler { /// /// From within the FFI module, we have no control over our memory lifecycle and we may get initialised multiple times within the same process. fn init_logging(log_dir: PathBuf, log_filter: String) -> Result<()> { - static LOGGER_STATE: OnceLock<( - firezone_logging::file::Handle, - firezone_logging::FilterReloadHandle, - )> = OnceLock::new(); - if let Some((_, reload_handle)) = LOGGER_STATE.get() { reload_handle .reload(&log_filter) @@ -323,6 +326,14 @@ impl WrappedSession { Ok(()) } + + fn set_log_directives(&mut self, directives: String) -> Result<()> { + let (_, handle) = LOGGER_STATE.get().context("Logger is not initialised")?; + + handle.reload(&directives)?; + + Ok(()) + } } impl Drop for WrappedSession { diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.h b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.h index 48809a030..c6b913c9b 100644 --- a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.h +++ b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.h @@ -15,5 +15,6 @@ struct __private__ResultPtrAndPtr __swift_bridge__$WrappedSession$connect(void* void __swift_bridge__$WrappedSession$reset(void* self); void* __swift_bridge__$WrappedSession$set_dns(void* self, void* dns_servers); void* __swift_bridge__$WrappedSession$set_disabled_resources(void* self, void* disabled_resources); +void* __swift_bridge__$WrappedSession$set_log_directives(void* self, void* directives); diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.swift b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.swift index f64d2e804..02818c3b4 100644 --- a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.swift +++ b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.swift @@ -49,6 +49,10 @@ extension WrappedSessionRefMut { public func setDisabledResources(_ disabled_resources: GenericIntoRustString) throws -> () { try { let val = __swift_bridge__$WrappedSession$set_disabled_resources(ptr, { let rustString = disabled_resources.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val != nil { throw RustString(ptr: val!) } else { return } }() } + + public func setLogDirectives(_ directives: GenericIntoRustString) throws -> () { + try { let val = __swift_bridge__$WrappedSession$set_log_directives(ptr, { let rustString = directives.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val != nil { throw RustString(ptr: val!) } else { return } }() + } } public class WrappedSessionRef { var ptr: UnsafeMutableRawPointer