ecli_lib/runner/
mod.rs

1//!  SPDX-License-Identifier: MIT
2//!
3//! Copyright (c) 2023, eunomia-bpf
4//! All rights reserved.
5//!
6use std::fmt::Display;
7
8/// APIs for client
9pub mod client;
10/// Some helper functions
11pub mod helper;
12/// APIs for http server
13#[cfg(feature = "http-server")]
14pub mod server_http;
15/// A helper to manage tasks running on this machine
16#[cfg(feature = "native-client")]
17pub mod task_manager;
18
19/// The handle type of a program
20pub type ProgramHandle = u64;
21
22/// A log entry
23#[derive(Debug, Clone)]
24pub struct LogEntry {
25    pub log: String,
26    pub timestamp: u64,
27    pub log_type: LogType,
28}
29
30impl Display for LogEntry {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        let time = chrono::NaiveDateTime::from_timestamp_micros((self.timestamp * 1000) as _)
33            .unwrap()
34            .format("%Y-%m-%d %H:%M:%S")
35            .to_string();
36        write!(f, "<{}> <{}> {}", time, self.log_type, self.log)
37    }
38}
39
40/// Type of a piece of log
41#[derive(Debug, Clone)]
42pub enum LogType {
43    Stdout,
44    Stderr,
45    Plain,
46}
47
48impl Display for LogType {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        match self {
51            LogType::Stdout => write!(f, "STDOUT"),
52            LogType::Stderr => write!(f, "STDERR"),
53            LogType::Plain => write!(f, "PLAIN"),
54        }
55    }
56}
57
58/// The default number og logs to poll
59pub const DEFAULT_MAXIMUM_LOG_ENTRIES: usize = 1000;