logging_util/lib.rs
1// Copyright 2026 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/// To properly bookend the logs even when we have an early disconnect, we have this struct which
6/// auto-logs on drop.
7pub struct FfxLogGuard<'a> {
8 log_id: &'a Option<String>,
9}
10
11impl<'a> FfxLogGuard<'a> {
12 pub fn new(log_id: &'a Option<String>) -> Self {
13 if let Some(log_id) = log_id {
14 log::info!("====> Starting ffx session: {}", log_id);
15 }
16 Self { log_id }
17 }
18}
19
20impl Drop for FfxLogGuard<'_> {
21 fn drop(&mut self) {
22 if let Some(log_id) = self.log_id {
23 log::info!("====> Ending ffx session: {}", log_id);
24 }
25 }
26}