-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into propogate_error_in_tokenization
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use serde::Serialize; | ||
|
||
pub mod event_logger; | ||
|
||
pub trait EventHandler: Sync + Send + dyn_clone::DynClone { | ||
fn log_event<T: Event>(&self, event: T, previous: Option<T>); | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum EventType { | ||
PaymentIntent, | ||
PaymentAttempt, | ||
Refund, | ||
ApiLogs, | ||
} | ||
|
||
pub trait Event | ||
where | ||
Self: Serialize, | ||
{ | ||
fn event_type() -> EventType; | ||
|
||
fn key(&self) -> String; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use super::{Event, EventHandler}; | ||
use crate::services::logger; | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct EventLogger {} | ||
|
||
impl EventHandler for EventLogger { | ||
fn log_event<T: Event>(&self, event: T, previous: Option<T>) { | ||
if let Some(prev) = previous { | ||
logger::info!(previous = ?serde_json::to_string(&prev).unwrap_or(r#"{ "error": "Serialization failed" }"#.to_string()), current = ?serde_json::to_string(&event).unwrap_or(r#"{ "error": "Serialization failed" }"#.to_string()), event_type =? T::event_type(), event_id =? event.key(), log_type = "event"); | ||
} else { | ||
logger::info!(current = ?serde_json::to_string(&event).unwrap_or(r#"{ "error": "Serialization failed" }"#.to_string()), event_type =? T::event_type(), event_id =? event.key(), log_type = "event"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters