Explorar o código

Android logging (#1533)

tsk hai 1 semana
pai
achega
526ce25fdc

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 160 - 135
Cargo.lock


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 162 - 134
Cargo.lock.msrv


+ 4 - 1
crates/cdk-cli/src/main.rs

@@ -134,7 +134,10 @@ async fn main() -> Result<()> {
     let env_filter = EnvFilter::new(format!("{default_filter},{filter}"));
 
     // Parse input
-    tracing_subscriber::fmt().with_env_filter(env_filter).init();
+    tracing_subscriber::fmt()
+        .with_env_filter(env_filter)
+        .with_ansi(false)
+        .init();
 
     let work_dir = match &args.work_dir {
         Some(work_dir) => work_dir.clone(),

+ 4 - 0
crates/cdk-ffi/Cargo.toml

@@ -33,6 +33,10 @@ cdk-common.workspace = true
 tracing.workspace = true
 tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }
 
+[target.'cfg(target_os = "android")'.dependencies]
+android_logger = "0.15"
+log = "0.4"
+
 
 [features]
 default = ["postgres"]

+ 7 - 7
crates/cdk-ffi/src/error.rs

@@ -12,20 +12,20 @@ use cdk_common::error::ErrorResponse;
 pub enum FfiError {
     /// CDK error with protocol-compliant error code
     /// The code corresponds to the Cashu protocol error codes (e.g., 11001, 20001, etc.)
-    #[error("[{code}] {message}")]
+    #[error("[{code}] {error_message}")]
     Cdk {
         /// Error code from the Cashu protocol specification
         code: u32,
         /// Human-readable error message
-        message: String,
+        error_message: String,
     },
 
     /// Internal/infrastructure error (no protocol error code)
     /// Used for errors that don't map to Cashu protocol codes
-    #[error("{message}")]
+    #[error("{error_message}")]
     Internal {
         /// Human-readable error message
-        message: String,
+        error_message: String,
     },
 }
 
@@ -33,7 +33,7 @@ impl FfiError {
     /// Create an internal error from any type that implements ToString
     pub fn internal(msg: impl ToString) -> Self {
         FfiError::Internal {
-            message: msg.to_string(),
+            error_message: msg.to_string(),
         }
     }
 
@@ -41,7 +41,7 @@ impl FfiError {
     pub fn database(msg: impl ToString) -> Self {
         FfiError::Cdk {
             code: 50000,
-            message: msg.to_string(),
+            error_message: msg.to_string(),
         }
     }
 }
@@ -51,7 +51,7 @@ impl From<CdkError> for FfiError {
         let response = ErrorResponse::from(err);
         FfiError::Cdk {
             code: response.code.to_code() as u32,
-            message: response.detail,
+            error_message: response.detail,
         }
     }
 }

+ 24 - 3
crates/cdk-ffi/src/logging.rs

@@ -28,11 +28,32 @@ static INIT: Once = std::sync::Once::new();
 #[uniffi::export]
 pub fn init_logging(level: String) {
     INIT.call_once(|| {
-        use tracing_subscriber::{fmt, EnvFilter};
+        #[cfg(target_os = "android")]
+        {
+            use android_logger::{Config, FilterBuilder};
+            use log::LevelFilter;
 
-        let filter = EnvFilter::try_new(&level).unwrap_or_else(|_| EnvFilter::new("info"));
+            android_logger::init_once(
+                Config::default()
+                    .with_max_level(LevelFilter::Trace)
+                    .with_tag("cdk")
+                    .with_format(|f, record| write!(f, "{}", record.args()))
+                    .with_filter(FilterBuilder::new().parse(&level).build()),
+            );
+        }
 
-        fmt().with_env_filter(filter).with_target(true).init();
+        #[cfg(not(target_os = "android"))]
+        {
+            use tracing_subscriber::{fmt, EnvFilter};
+
+            let filter = EnvFilter::try_new(&level).unwrap_or_else(|_| EnvFilter::new("info"));
+
+            fmt()
+                .with_env_filter(filter)
+                .with_target(true)
+                .with_ansi(false)
+                .init();
+        }
     });
 }
 

+ 1 - 0
crates/cdk-mint-rpc/src/bin/mint_rpc_cli.rs

@@ -40,6 +40,7 @@ pub fn init_logging(enable_logging: bool, log_level: tracing::Level) {
         // Ok if successful, Err if already initialized
         let _ = tracing_subscriber::fmt()
             .with_env_filter(env_filter)
+            .with_ansi(false)
             .try_init();
     }
 }

+ 3 - 0
crates/cdk-mintd/src/lib.rs

@@ -141,6 +141,7 @@ pub fn setup_tracing(
 
             tracing_subscriber::fmt()
                 .with_env_filter(env_filter)
+                .with_ansi(false)
                 .with_writer(stderr)
                 .init();
 
@@ -168,6 +169,7 @@ pub fn setup_tracing(
 
             tracing_subscriber::fmt()
                 .with_env_filter(env_filter)
+                .with_ansi(false)
                 .with_writer(file_writer)
                 .init();
 
@@ -207,6 +209,7 @@ pub fn setup_tracing(
 
             tracing_subscriber::fmt()
                 .with_env_filter(env_filter)
+                .with_ansi(false)
                 .with_writer(stderr.and(file_writer))
                 .init();
 

+ 1 - 0
crates/cdk-payment-processor/src/bin/payment_processor.rs

@@ -53,6 +53,7 @@ pub fn init_logging(enable_logging: bool, log_level: tracing::Level) {
         // Ok if successful, Err if already initialized
         let _ = tracing_subscriber::fmt()
             .with_env_filter(env_filter)
+            .with_ansi(false)
             .try_init();
     }
 }

+ 1 - 0
crates/cdk-signatory/src/bin/cli/mod.rs

@@ -50,6 +50,7 @@ pub fn init_logging(enable_logging: bool, log_level: tracing::Level) {
         // Ok if successful, Err if already initialized
         let _ = tracing_subscriber::fmt()
             .with_env_filter(env_filter)
+            .with_ansi(false)
             .try_init();
     }
 }

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio