Skip to content

Commit

Permalink
UniFFI export function to enable rust logging (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX authored May 11, 2024
1 parent 3d7d351 commit 02c6405
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUST_LOG=info
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sargon"
version = "0.7.12"
version = "0.7.13"
edition = "2021"
build = "build.rs"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Once;

use crate::prelude::*;

#[uniffi::export]
Expand All @@ -10,6 +12,25 @@ pub fn new_sargon_build_information_sample_other() -> SargonBuildInformation {
SargonBuildInformation::sample_other()
}

#[uniffi::export]
pub fn enable_logging_from_rust() {
init_logging()
}

/// Initializes logging
#[cfg(not(tarpaulin_include))] // actually tricky, since we init logging from other unit tests -> crash.
pub fn init_logging() {
static ONCE: Once = Once::new();
ONCE.call_once(|| {
let level = log::LevelFilter::Trace;
pretty_env_logger::formatted_builder()
.filter_level(level)
.try_init()
.expect("Should be able to setup a logger.");
info!("Rust: Logger initialized, log level: {:?}", level);
});
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 02c6405

Please sign in to comment.