use async_trait::async_trait;
use super::LogRecord;
use crate::core::{Error, Result};
#[derive(Debug, Default)]
pub struct ExportResult {
pub accepted: usize,
pub rejected: usize,
pub error: Option<Error>,
}
impl ExportResult {
pub fn accepted(n: usize) -> Self {
ExportResult {
accepted: n,
..Default::default()
}
}
pub fn partial(accepted: usize, rejected: usize, error: Option<Error>) -> Self {
ExportResult {
accepted,
rejected,
error,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ExportOptions {
pub gzip: bool,
}
impl ExportOptions {
pub fn new(gzip: bool) -> Self {
ExportOptions { gzip }
}
}
impl Default for ExportOptions {
fn default() -> Self {
ExportOptions { gzip: true }
}
}
#[async_trait]
pub trait LogExporter: Send + Sync {
async fn export(&self, records: &[LogRecord], opts: ExportOptions) -> Result<ExportResult>;
async fn shutdown(&self) -> Result<()> {
Ok(())
}
}