Add async batching and flush policies

This commit is contained in:
Nanaloveyuki
2026-05-08 18:52:50 +08:00
parent 95ccb72093
commit 87e5491801
3 changed files with 140 additions and 3 deletions
+23 -1
View File
@@ -8,16 +8,31 @@ pub(all) enum AsyncOverflowPolicy {
DropNewest
}
pub(all) enum AsyncFlushPolicy {
Never
Batch
Shutdown
}
pub struct AsyncLoggerConfig {
max_pending : Int
overflow : AsyncOverflowPolicy
max_batch : Int
flush : AsyncFlushPolicy
}
pub fn AsyncLoggerConfig::new(
max_pending~ : Int = 0,
overflow~ : AsyncOverflowPolicy = AsyncOverflowPolicy::Blocking,
max_batch~ : Int = 1,
flush~ : AsyncFlushPolicy = AsyncFlushPolicy::Never,
) -> AsyncLoggerConfig {
{ max_pending, overflow }
{
max_pending,
overflow,
max_batch: if max_batch <= 1 { 1 } else { max_batch },
flush,
}
}
pub struct AsyncLogger[S] {}
@@ -76,11 +91,13 @@ pub fn async_logger[S : @bitlogger.Sink](
config~ : AsyncLoggerConfig = AsyncLoggerConfig::new(),
min_level~ : @bitlogger.Level = @bitlogger.Level::Info,
target~ : String = "",
flush~ : (S) -> Int = fn(_) { 0 },
) -> AsyncLogger[S] {
ignore(sink)
ignore(config)
ignore(min_level)
ignore(target)
ignore(flush)
abort("bitlogger_async currently only supports native/llvm backends")
}
@@ -174,6 +191,11 @@ pub fn[S] AsyncLogger::last_error(self : AsyncLogger[S]) -> String {
abort("bitlogger_async currently only supports native/llvm backends")
}
pub fn[S] AsyncLogger::flush_policy(self : AsyncLogger[S]) -> AsyncFlushPolicy {
ignore(self)
abort("bitlogger_async currently only supports native/llvm backends")
}
pub fn[S] AsyncLogger::close(self : AsyncLogger[S], clear? : Bool = false) -> Unit {
ignore(self)
ignore(clear)