Skip to content

Commit

Permalink
chore: Use the pact_matcing LOG_ID in the FFI inmem logging functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Sep 5, 2024
1 parent 1686185 commit 9d3610d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions rust/pact_ffi/src/log/inmem_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::sync::Mutex;

use bytes::{BufMut, Bytes, BytesMut};
use lazy_static::lazy_static;
use tokio::task_local;
use tracing_subscriber::fmt::MakeWriter;

/// In-memory buffer for logging output. Sends output to global static `LOG_BUFFER` in the pact_matching
Expand Down Expand Up @@ -47,11 +46,13 @@ lazy_static! {
static ref LOG_BUFFER: Mutex<HashMap<String, BytesMut>> = Mutex::new(HashMap::new());
}

task_local! {
/// Log ID to accumulate logs against
#[allow(missing_docs)]
pub static LOG_ID: String;
}
// TODO: This needs to be moved from pact_matching, but at the moment the mock server crate
// relies on it
// task_local! {
// /// Log ID to accumulate logs against
// #[allow(missing_docs)]
// pub static LOG_ID: String;
// }

/// Fetches the contents from the id scoped in-memory buffer and empties the buffer.
pub fn fetch_buffer_contents(id: &str) -> Bytes {
Expand All @@ -64,7 +65,9 @@ pub fn fetch_buffer_contents(id: &str) -> Bytes {
/// Writes the provided bytes to the task local ID scoped in-memory buffer. If there is no
/// task local ID set, will write to the "global" buffer.
pub fn write_to_log_buffer(buf: &[u8]) {
let id = LOG_ID.try_with(|id| id.clone()).unwrap_or_else(|_| "global".into());
let id = pact_matching::logging::LOG_ID
.try_with(|id| id.clone())
.unwrap_or_else(|_| "global".into());
let mut inner = LOG_BUFFER.lock().unwrap();
let buffer = inner.entry(id)
.or_insert_with(|| BytesMut::with_capacity(256));
Expand Down

0 comments on commit 9d3610d

Please sign in to comment.