Skip to content

Commit

Permalink
Fix storage logger (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr authored Dec 10, 2024
1 parent 58d0daf commit f0fd581
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions mutiny-core/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ const MAX_LOG_ITEMS: usize = 10_000;
#[derive(Clone)]
pub struct MutinyLogger {
pub session_id: String,
should_write_to_storage: bool,
should_write: bool,
should_persist: bool,
memory_logs: Arc<Mutex<Vec<String>>>,
stop_handle: Option<StopHandle>,
}

impl MutinyLogger {
pub fn memory_only() -> Self {
Self {
should_persist: false,
should_write: true,
..Default::default()
}
}

pub fn with_writer<S: MutinyStorage>(
logging_db: S,
session_id: Option<String>,
Expand Down Expand Up @@ -72,7 +81,8 @@ impl MutinyLogger {

MutinyLogger {
session_id: session_id.unwrap_or_else(gen_session_id),
should_write_to_storage: true,
should_write: true,
should_persist: true,
memory_logs,
stop_handle: Some(stop_handle),
}
Expand All @@ -91,7 +101,7 @@ impl MutinyLogger {
&self,
storage: &S,
) -> Result<Option<Vec<String>>, MutinyError> {
if !self.should_write_to_storage {
if !self.should_write || !self.should_persist {
return Ok(None);
}
get_logging_data(storage)
Expand All @@ -108,7 +118,8 @@ impl Default for MutinyLogger {
fn default() -> Self {
Self {
session_id: gen_session_id(),
should_write_to_storage: Default::default(),
should_write: false,
should_persist: false,
memory_logs: Arc::new(Mutex::new(vec![])),
stop_handle: None,
}
Expand Down Expand Up @@ -139,7 +150,7 @@ impl Logger for MutinyLogger {
raw_log
);

if self.should_write_to_storage && record.level >= Level::Trace {
if self.should_write && record.level >= Level::Trace {
if let Ok(mut memory_logs) = self.memory_logs.lock() {
memory_logs.push(log.clone());
} else {
Expand Down
2 changes: 1 addition & 1 deletion mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl MutinyWallet {
ln_event_callback: Option<CommonLnEventCallback>,
) -> Result<MutinyWallet, MutinyJsError> {
let safe_mode = safe_mode.unwrap_or(false);
let logger = Arc::new(MutinyLogger::default());
let logger = Arc::new(MutinyLogger::memory_only());

let cipher = password
.as_ref()
Expand Down

0 comments on commit f0fd581

Please sign in to comment.