vmgs/logger.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! The definition of `VmgsLogger` trait that enables VMGS implementation
5//! to send log events to an external logger.
6
7use std::sync::Arc;
8
9/// List of events for `VmgsLogger`.
10pub enum VmgsLogEvent {
11 /// VMGS initialization failed.
12 InitFailed,
13 /// Invalid VMGS file format.
14 InvalidFormat,
15 /// Corrupt VMGS file format.
16 CorruptFormat,
17 /// Data store access failure.
18 AccessFailed,
19}
20
21/// A trait for sending log event to the host.
22#[async_trait::async_trait]
23pub trait VmgsLogger: Send + Sync {
24 /// Send a fatal event with the given id to the host.
25 async fn log_event_fatal(&self, event: VmgsLogEvent);
26}
27
28#[async_trait::async_trait]
29impl VmgsLogger for Option<Arc<dyn VmgsLogger>> {
30 async fn log_event_fatal(&self, event: VmgsLogEvent) {
31 if let Some(logger) = self {
32 logger.log_event_fatal(event).await;
33 }
34 }
35}