wlan_telemetry/util/
cobalt_logger.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2024 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Macro wrapper for logging simple events (occurrence, integer, histogram, string)
/// and log a warning when the status is not Ok.
// TODO(339221340): remove these allows once the skeleton has a few uses
#[allow(unused)]
macro_rules! log_cobalt_1dot1 {
    ($cobalt_proxy:expr, $method_name:ident, $metric_id:expr, $value:expr, $event_codes:expr $(,)?) => {{
        let status = $cobalt_proxy.$method_name($metric_id, $value, $event_codes).await;
        match status {
            Ok(Ok(())) => (),
            Ok(Err(e)) => tracing::info!("Failed logging metric: {}, error: {:?}", $metric_id, e),
            Err(e) => tracing::info!("Failed logging metric: {}, error: {}", $metric_id, e),
        }
    }};
}

macro_rules! log_cobalt_1dot1_batch {
    ($cobalt_proxy:expr, $events:expr, $context:expr $(,)?) => {{
        let status = $cobalt_proxy.log_metric_events($events).await;
        match status {
            Ok(Ok(())) => (),
            Ok(Err(e)) => {
                tracing::info!(
                    "Failed logging batch metrics, context: {}, error: {:?}",
                    $context,
                    e
                );
            }
            Err(e) => {
                tracing::info!("Failed logging batch metrics, context: {}, error: {}", $context, e)
            }
        }
    }};
}

// TODO(339221340): remove these allows once the skeleton has a few uses
#[allow(unused)]
pub(crate) use {log_cobalt_1dot1, log_cobalt_1dot1_batch};