| 19 | } |
| 20 | |
| 21 | pub fn logger<T>(target_fn: &'static str, context: &CallContext, result: Option<&T>) |
| 22 | where |
| 23 | T: std::fmt::Debug, |
| 24 | { |
| 25 | match result { |
| 26 | Some(result) => { |
| 27 | ic_cdk::api::print( |
| 28 | serde_json::to_string(&LogMessage { |
| 29 | function: target_fn.to_string(), |
| 30 | message: format!("completed execution with result {result:?}"), |
| 31 | timestamp: ic_cdk::api::time(), |
| 32 | caller: context.caller().to_text(), |
| 33 | }) |
| 34 | .expect("Failed to serialize log message"), |
| 35 | ); |
| 36 | } |
| 37 | None => { |
| 38 | ic_cdk::api::print( |
| 39 | serde_json::to_string(&LogMessage { |
| 40 | function: target_fn.to_string(), |
| 41 | message: "started execution".to_string(), |
| 42 | timestamp: ic_cdk::api::time(), |
| 43 | caller: context.caller().to_text(), |
| 44 | }) |
| 45 | .expect("Failed to serialize log message"), |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | pub fn use_canister_call_metric<T>(called_method: &str, result: &ApiResult<T>) |
| 52 | where |