Skip to main content

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#[allow(clippy::double_must_use)]
17#[async_trait]
18pub trait LogManager: Send + Sync {
19    /// Request to host to fetch logs.
20    ///
21    /// The `PermissionLogView` permission is required to call this method.
22    async fn log_get(&self, args: LogGetRequest) -> Result<LogGetResponse, Error>;
23}
24
25#[allow(clippy::double_must_use)]
26#[async_trait]
27impl LogManager for Protocol {
28    async fn log_get(&self, args: LogGetRequest) -> Result<LogGetResponse, Error> {
29        host_rpc_call(self, LOCAL_RPC_ENDPOINT_LOG_MANAGER, METHOD_LOG_GET, args).await
30    }
31}
32
33/// Request to fetch logs.
34///
35/// The `PermissionLogView` permission is required to call this method.
36#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
37pub struct LogGetRequest {
38    /// Labels to filter the bundles by. All labels must match and only the first bundle is used.
39    pub labels: BTreeMap<String, String>,
40    /// Identifier of the component in the bundle.
41    pub component_id: String,
42    /// An optional UNIX timestamp to filter log entries by. Only entries with higher timestamps
43    /// will be returned.
44    #[cbor(optional)]
45    pub since: u64,
46}
47
48/// Response from the LogGet method.
49#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
50pub struct LogGetResponse {
51    /// Log lines for the given component.
52    pub logs: Vec<String>,
53}