Extract value from a log line given a key (copied from alloy-node-bindings utils.rs)
(key: &str, line: &'a str)
| 38 | |
| 39 | /// Extract value from a log line given a key (copied from alloy-node-bindings utils.rs) |
| 40 | fn extract_value<'a>(key: &str, line: &'a str) -> Option<&'a str> { |
| 41 | let mut key_equal = Cow::from(key); |
| 42 | let mut key_colon = Cow::from(key); |
| 43 | |
| 44 | // Prepare both key variants |
| 45 | if !key_equal.ends_with('=') { |
| 46 | key_equal = format!("{}=", key).into(); |
| 47 | } |
| 48 | if !key_colon.ends_with(": ") { |
| 49 | key_colon = format!("{}: ", key).into(); |
| 50 | } |
| 51 | |
| 52 | // Try to find the key with '=' |
| 53 | if let Some(pos) = line.find(key_equal.as_ref()) { |
| 54 | let start = pos + key_equal.len(); |
| 55 | let end = line[start..] |
| 56 | .find(' ') |
| 57 | .map(|i| start + i) |
| 58 | .unwrap_or(line.len()); |
| 59 | if start <= line.len() && end <= line.len() { |
| 60 | return Some(line[start..end].trim()); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // If not found, try to find the key with ': ' |
| 65 | if let Some(pos) = line.find(key_colon.as_ref()) { |
| 66 | let start = pos + key_colon.len(); |
| 67 | let end = line[start..] |
| 68 | .find(',') |
| 69 | .map(|i| start + i) |
| 70 | .unwrap_or(line.len()); |
| 71 | if start <= line.len() && end <= line.len() { |
| 72 | return Some(line[start..end].trim()); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // If neither variant matches, return None |
| 77 | None |
| 78 | } |
| 79 | |
| 80 | /// Extract endpoint from a log line (copied from alloy-node-bindings utils.rs) |
| 81 | fn extract_endpoint(key: &str, line: &str) -> Option<SocketAddr> { |