pub mod circuit_breaker;
pub mod compression;
pub mod console;
#[cfg(any(
feature = "sqlite",
feature = "postgres",
feature = "mysql",
feature = "duckdb"
))]
pub mod database;
pub mod encryption;
#[cfg(any(
feature = "sqlite",
feature = "postgres",
feature = "mysql",
feature = "duckdb"
))]
pub mod entity;
pub mod file;
pub mod registry;
pub mod ring_buffered_file;
pub mod rotation;
pub use circuit_breaker::{CircuitBreaker, CircuitBreakerConfig, CircuitState};
#[cfg(feature = "compression")]
pub use compression::ZstdCompression;
pub use compression::{CompressionStrategy, GzipCompression, NoCompression};
pub use console::ConsoleSink;
#[cfg(any(
feature = "sqlite",
feature = "postgres",
feature = "mysql",
feature = "duckdb"
))]
pub use database::DatabaseSink;
pub use file::FileSink;
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>;
}
pub trait Rotatable {
fn start_rotation_timer(&self);
fn stop_rotation_timer(&self);
}
pub trait DiskCheckable {
fn check_disk_space(&self) -> Result<bool, InklogError>;
}
#[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());
}
struct RotatableDiskSink;
#[async_trait]
impl LogSink for RotatableDiskSink {
async fn write(&self, _record: &LogRecord) -> Result<(), InklogError> {
Ok(())
}
async fn flush(&self) -> Result<(), InklogError> {
Ok(())
}
async fn shutdown(&self) -> Result<(), InklogError> {
Ok(())
}
}
impl Rotatable for RotatableDiskSink {
fn start_rotation_timer(&self) {}
fn stop_rotation_timer(&self) {}
}
impl DiskCheckable for RotatableDiskSink {
fn check_disk_space(&self) -> Result<bool, InklogError> {
Ok(true)
}
}
#[test]
fn test_rotatable_trait() {
let sink = RotatableDiskSink;
sink.start_rotation_timer();
sink.stop_rotation_timer();
}
#[test]
fn test_disk_checkable_trait() {
let sink = RotatableDiskSink;
let result = sink.check_disk_space();
assert!(result.is_ok());
assert!(result.unwrap());
}
#[test]
fn test_log_sink_does_not_have_rotation_or_disk() {
let sink = DummySink;
assert!(sink.is_healthy());
}
}