From 66567f8474755dc0d96390c91bc669cf8ab48f65 Mon Sep 17 00:00:00 2001 From: jerel Date: Tue, 29 Aug 2023 15:32:36 -0500 Subject: [PATCH] Adjust dart config --- membrane/src/generators/functions.rs | 8 ++++---- membrane/src/generators/loaders.rs | 8 ++++---- membrane/src/lib.rs | 22 ++++++++++++++-------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/membrane/src/generators/functions.rs b/membrane/src/generators/functions.rs index 6856d6b..bd86557 100644 --- a/membrane/src/generators/functions.rs +++ b/membrane/src/generators/functions.rs @@ -315,7 +315,7 @@ impl Callable for Ffi { } else { String::from(", ") + self.fun.dart_inner_args }, - fine_logger = config.dart_config.fine_log_fn + fine_logger = config.dart_config.logger.fine_log_fn ) .as_str(); self @@ -350,7 +350,7 @@ impl Callable for Ffi { error_de = self.fun.deserializer(self.fun.error_type, enum_tracer_registry, config), class_name = self.fun.namespace.to_upper_camel_case(), fn_name = self.fun.fn_name, - fine_logger = config.dart_config.fine_log_fn + fine_logger = config.dart_config.logger.fine_log_fn ) } else if self.fun.is_stream { format!( @@ -383,7 +383,7 @@ impl Callable for Ffi { // having all streams auto-disconnect after a pause in events is not desirable "".to_string() }, - fine_logger = config.dart_config.fine_log_fn + fine_logger = config.dart_config.logger.fine_log_fn ) } else { format!( @@ -422,7 +422,7 @@ impl Callable for Ffi { // and by default we won't time out at all "".to_string() }, - fine_logger = config.dart_config.fine_log_fn + fine_logger = config.dart_config.logger.fine_log_fn ) } .as_str(); diff --git a/membrane/src/generators/loaders.rs b/membrane/src/generators/loaders.rs index 9cb09d7..cb3981b 100644 --- a/membrane/src/generators/loaders.rs +++ b/membrane/src/generators/loaders.rs @@ -74,10 +74,10 @@ bool bindingsLoaded = false; final bindings = _load(); "#, lib = library, - logger_path = dart_config.logger_import_path, - logger = dart_config.logger, - info_logger = dart_config.info_log_fn, - fine_logger = dart_config.fine_log_fn, + logger_path = dart_config.logger.import_path, + logger = dart_config.logger.instance, + info_logger = dart_config.logger.info_log_fn, + fine_logger = dart_config.logger.fine_log_fn, ) } diff --git a/membrane/src/lib.rs b/membrane/src/lib.rs index 869621b..9ddb06e 100644 --- a/membrane/src/lib.rs +++ b/membrane/src/lib.rs @@ -105,19 +105,24 @@ use std::{ }; use tracing::{debug, info, warn}; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct DartConfig { - pub logger_import_path: &'static str, - pub logger: &'static str, + pub logger: DartLoggerConfig, +} + +#[derive(Debug)] +pub struct DartLoggerConfig { + pub import_path: &'static str, + pub instance: &'static str, pub info_log_fn: &'static str, pub fine_log_fn: &'static str, } -impl Default for DartConfig { +impl Default for DartLoggerConfig { fn default() -> Self { Self { - logger_import_path: "package:logging/logging.dart", - logger: "Logger('membrane')", + import_path: "package:logging/logging.dart", + instance: "Logger('membrane')", info_log_fn: "info", fine_log_fn: "fine", } @@ -567,7 +572,7 @@ impl<'a> Membrane { /// Default: /// /// DartConfig { - /// logger_import_path: "package:logging/logging.dart", + /// import_path: "package:logging/logging.dart", /// logger: "Logger('membrane')", /// info_log_fn: "info", /// fine_log_fn: "fine", @@ -978,10 +983,11 @@ class {class_name}Api {{ "#, ns = &namespace, class_name = &namespace.to_upper_camel_case(), - logger_path = self.dart_config.logger_import_path, + logger_path = self.dart_config.logger.import_path, logger = self .dart_config .logger + .instance .replace("')", &format!(".{}')", &namespace)) .replace("\")", &format!(".{}\")", &namespace)), );