pub mod circuit_breaker;
pub mod compression;
pub mod console;
#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
pub mod database;
pub mod encryption;
#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
pub mod entity;
pub mod file;
pub mod registry;
pub mod ring_buffered_file;
pub mod rotation;
pub use compression::{CompressionStrategy, GzipCompression, NoCompression, ZstdCompression};
pub use registry::{FileSinkFactory, SinkFactory, SinkMetadata, SinkRegistry};
pub use rotation::{
CompositeRotation, RotationContext, RotationResult, RotationStrategy, SizeBasedRotation,
TimeBasedRotation,
};
use crate::InklogError;
use crate::LogRecord;
use async_trait::async_trait;
#[async_trait]
pub trait LogSink: Send + Sync {
async fn write(&self, record: &LogRecord) -> Result<(), InklogError>;
async fn flush(&self) -> Result<(), InklogError>;
fn is_healthy(&self) -> bool {
true
}
async fn shutdown(&self) -> Result<(), InklogError>;
fn start_rotation_timer(&self) {
}
fn stop_rotation_timer(&self) {
}
fn check_disk_space(&self) -> Result<bool, InklogError> {
Ok(true) }
}
#[cfg(test)]
mod tests {
use super::*;
struct DummySink;
#[async_trait]
impl LogSink for DummySink {
async fn write(&self, _record: &LogRecord) -> Result<(), InklogError> {
Ok(())
}
async fn flush(&self) -> Result<(), InklogError> {
Ok(())
}
async fn shutdown(&self) -> Result<(), InklogError> {
Ok(())
}
}
#[test]
fn test_default_is_healthy() {
let sink = DummySink;
assert!(sink.is_healthy());
}
#[test]
fn test_default_start_rotation_timer() {
let sink = DummySink;
sink.start_rotation_timer();
}
#[test]
fn test_default_stop_rotation_timer() {
let sink = DummySink;
sink.stop_rotation_timer();
}
#[test]
fn test_default_check_disk_space() {
let sink = DummySink;
let result = sink.check_disk_space();
assert!(result.is_ok());
assert!(result.unwrap());
}
}