oasis_core_runtime/host/
log_manager.rs

1use std::collections::BTreeMap;
2
3use async_trait::async_trait;
4
5use crate::protocol::Protocol;
6
7use super::{host_rpc_call, Error};
8
9/// Name of the local RPC endpoint for the log manager.
10pub const LOCAL_RPC_ENDPOINT_LOG_MANAGER: &str = "log-manager";
11
12/// Name of the LogGet method.
13pub const METHOD_LOG_GET: &str = "LogGet";
14
15/// Log manager interface.
16#[async_trait]
17pub trait LogManager: Send + Sync {
18    /// Request to host to fetch logs.
19    ///
20    /// The `PermissionLogView` permission is required to call this method.
21    async fn log_get(&self, args: LogGetRequest) -> Result<LogGetResponse, Error>;
22}
23
24#[async_trait]
25impl LogManager for Protocol {
26    async fn log_get(&self, args: LogGetRequest) -> Result<LogGetResponse, Error> {
27        host_rpc_call(self, LOCAL_RPC_ENDPOINT_LOG_MANAGER, METHOD_LOG_GET, args).await
28    }
29}
30
31/// Request to fetch logs.
32///
33/// The `PermissionLogView` permission is required to call this method.
34#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
35pub struct LogGetRequest {
36    /// Labels to filter the bundles by. All labels must match and only the first bundle is used.
37    pub labels: BTreeMap<String, String>,
38    /// Identifier of the component in the bundle.
39    pub component_id: String,
40    /// An optional UNIX timestamp to filter log entries by. Only entries with higher timestamps
41    /// will be returned.
42    #[cbor(optional)]
43    pub since: u64,
44}
45
46/// Response from the LogGet method.
47#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
48pub struct LogGetResponse {
49    /// Log lines for the given component.
50    pub logs: Vec<String>,
51}