wlan_telemetry/util/
cobalt_logger.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/// Macro wrapper for logging simple events (occurrence, integer, histogram, string)
6/// and log a warning when the status is not Ok.
7// TODO(339221340): remove these allows once the skeleton has a few uses
8#[allow(unused)]
9macro_rules! log_cobalt {
10    ($cobalt_proxy:expr, $method_name:ident, $metric_id:expr, $value:expr, $event_codes:expr $(,)?) => {{
11        let status = $cobalt_proxy.$method_name($metric_id, $value, $event_codes).await;
12        match status {
13            Ok(Ok(())) => (),
14            Ok(Err(e)) => log::info!("Failed logging metric: {}, error: {:?}", $metric_id, e),
15            Err(e) => log::info!("Failed logging metric: {}, error: {}", $metric_id, e),
16        }
17    }};
18}
19
20macro_rules! log_cobalt_batch {
21    ($cobalt_proxy:expr, $events:expr, $context:expr $(,)?) => {{
22        if !$events.is_empty() {
23            let status = $cobalt_proxy.log_metric_events($events).await;
24            match status {
25                Ok(Ok(())) => (),
26                Ok(Err(e)) => {
27                    log::info!(
28                        "Failed logging batch metrics, context: {}, error: {:?}",
29                        $context,
30                        e
31                    );
32                }
33                Err(e) => {
34                    log::info!("Failed logging batch metrics, context: {}, error: {}", $context, e)
35                }
36            }
37        }
38    }};
39}
40
41// TODO(339221340): remove these allows once the skeleton has a few uses
42#[allow(unused)]
43pub(crate) use {log_cobalt, log_cobalt_batch};