| 104 | impl<T, E: std::fmt::Display> LogExt<T, E> for Result<T, E> { |
| 105 | #[track_caller] |
| 106 | fn log_err(self, context: &Context) -> Result<T, E> { |
| 107 | if let Err(e) = &self { |
| 108 | let location = std::panic::Location::caller(); |
| 109 | |
| 110 | // We are using Anyhow's .context() and to show the inner error, too, we need the {:#}: |
| 111 | let full = format!( |
| 112 | "{file}:{line}: {e:#}", |
| 113 | file = location.file(), |
| 114 | line = location.line(), |
| 115 | e = e |
| 116 | ); |
| 117 | // We can't use the warn!() macro here as the file!() and line!() macros |
| 118 | // don't work with #[track_caller] |
| 119 | tracing::event!( |
| 120 | ::tracing::Level::WARN, |
| 121 | account_id = context.get_id(), |
| 122 | "{}", |
| 123 | &full |
| 124 | ); |
| 125 | context.emit_event(crate::EventType::Warning(full)); |
| 126 | }; |
| 127 | self |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | #[cfg(test)] |