mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
⬆️ Update MoonBit Version to v0.9.2 and Fix warns
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
async test "shutdown drains pending records" {
|
async test "shutdown drains pending records" {
|
||||||
inspect(async_runtime_mode_label(async_runtime_mode()) == "native_worker" || async_runtime_mode_label(async_runtime_mode()) == "compatibility", content="true")
|
inspect(async_runtime_mode_label(async_runtime_mode()) == "native_worker" || async_runtime_mode_label(async_runtime_mode()) == "compatibility", content="true")
|
||||||
let written : Ref[Array[String]] = Ref::new([])
|
let written : Ref[Array[String]] = Ref([])
|
||||||
let flushes : Ref[Int] = Ref::new(0)
|
let flushes : Ref[Int] = Ref(0)
|
||||||
let logger = async_logger(
|
let logger = async_logger(
|
||||||
@bitlogger.callback_sink(fn(rec) {
|
@bitlogger.callback_sink(fn(rec) {
|
||||||
written.val.push(rec.message)
|
written.val.push(rec.message)
|
||||||
@@ -212,7 +212,7 @@ test "async logger state snapshot reflects current counters and runtime" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async test "run drains queued records in compatibility backends too" {
|
async test "run drains queued records in compatibility backends too" {
|
||||||
let written : Ref[Array[String]] = Ref::new([])
|
let written : Ref[Array[String]] = Ref([])
|
||||||
let logger = async_logger(
|
let logger = async_logger(
|
||||||
@bitlogger.callback_sink(fn(rec) {
|
@bitlogger.callback_sink(fn(rec) {
|
||||||
written.val.push(rec.message)
|
written.val.push(rec.message)
|
||||||
@@ -244,9 +244,9 @@ async test "run drains queued records in compatibility backends too" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async test "library async logger keeps a smaller async facade" {
|
async test "library async logger keeps a smaller async facade" {
|
||||||
let written_targets : Ref[Array[String]] = Ref::new([])
|
let written_targets : Ref[Array[String]] = Ref([])
|
||||||
let written_messages : Ref[Array[String]] = Ref::new([])
|
let written_messages : Ref[Array[String]] = Ref([])
|
||||||
let written_field_counts : Ref[Array[Int]] = Ref::new([])
|
let written_field_counts : Ref[Array[Int]] = Ref([])
|
||||||
let logger = LibraryAsyncLogger::new(
|
let logger = LibraryAsyncLogger::new(
|
||||||
@bitlogger.callback_sink(fn(rec) {
|
@bitlogger.callback_sink(fn(rec) {
|
||||||
written_targets.val.push(rec.target)
|
written_targets.val.push(rec.target)
|
||||||
|
|||||||
@@ -323,12 +323,12 @@ pub fn[S] async_logger(
|
|||||||
filter: fn(_) { true },
|
filter: fn(_) { true },
|
||||||
patch: @bitlogger.identity_patch(),
|
patch: @bitlogger.identity_patch(),
|
||||||
queue: @async.Queue(kind=queue_kind_of(config)),
|
queue: @async.Queue(kind=queue_kind_of(config)),
|
||||||
pending_count: Ref::new(0),
|
pending_count: Ref(0),
|
||||||
dropped_count: Ref::new(0),
|
dropped_count: Ref(0),
|
||||||
is_closed: Ref::new(false),
|
is_closed: Ref(false),
|
||||||
is_running: Ref::new(false),
|
is_running: Ref(false),
|
||||||
has_failed: Ref::new(false),
|
has_failed: Ref(false),
|
||||||
last_error: Ref::new(""),
|
last_error: Ref(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -772,9 +772,9 @@ test "configured queued file logger flushes queue through file helper" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "library logger keeps a smaller stable facade" {
|
test "library logger keeps a smaller stable facade" {
|
||||||
let captured_target : Ref[String] = Ref::new("")
|
let captured_target : Ref[String] = Ref("")
|
||||||
let captured_message : Ref[String] = Ref::new("")
|
let captured_message : Ref[String] = Ref("")
|
||||||
let captured_fields : Ref[Array[Field]] = Ref::new([])
|
let captured_fields : Ref[Array[Field]] = Ref([])
|
||||||
let logger = LibraryLogger::new(
|
let logger = LibraryLogger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
captured_target.val = rec.target
|
captured_target.val = rec.target
|
||||||
|
|||||||
+29
-29
@@ -351,7 +351,7 @@ test "text formatter template respects disabled fields" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "formatted callback sink receives rendered text" {
|
test "formatted callback sink receives rendered text" {
|
||||||
let rendered : Ref[String] = Ref::new("")
|
let rendered : Ref[String] = Ref("")
|
||||||
let sink = text_callback_sink(
|
let sink = text_callback_sink(
|
||||||
text_formatter(show_timestamp=false, separator=" | "),
|
text_formatter(show_timestamp=false, separator=" | "),
|
||||||
fn(text) {
|
fn(text) {
|
||||||
@@ -620,8 +620,8 @@ test "json formatter keeps structured shape" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "callback sink receives record" {
|
test "callback sink receives record" {
|
||||||
let captured_target : Ref[String] = Ref::new("")
|
let captured_target : Ref[String] = Ref("")
|
||||||
let captured_message : Ref[String] = Ref::new("")
|
let captured_message : Ref[String] = Ref("")
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
captured_target.val = rec.target
|
captured_target.val = rec.target
|
||||||
@@ -636,8 +636,8 @@ test "callback sink receives record" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "split sink routes records by predicate" {
|
test "split sink routes records by predicate" {
|
||||||
let left_messages : Ref[Array[String]] = Ref::new([])
|
let left_messages : Ref[Array[String]] = Ref([])
|
||||||
let right_messages : Ref[Array[String]] = Ref::new([])
|
let right_messages : Ref[Array[String]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
split_sink(
|
split_sink(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
@@ -662,8 +662,8 @@ test "split sink routes records by predicate" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "split_by_level routes warn and error separately" {
|
test "split_by_level routes warn and error separately" {
|
||||||
let high_messages : Ref[Array[String]] = Ref::new([])
|
let high_messages : Ref[Array[String]] = Ref([])
|
||||||
let low_messages : Ref[Array[String]] = Ref::new([])
|
let low_messages : Ref[Array[String]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
split_by_level(
|
split_by_level(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
@@ -688,10 +688,10 @@ test "split_by_level routes warn and error separately" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "callback sink sees child target and context logger shape" {
|
test "callback sink sees child target and context logger shape" {
|
||||||
let captured_target : Ref[String] = Ref::new("")
|
let captured_target : Ref[String] = Ref("")
|
||||||
let captured_message : Ref[String] = Ref::new("")
|
let captured_message : Ref[String] = Ref("")
|
||||||
let captured_field_count : Ref[Int] = Ref::new(0)
|
let captured_field_count : Ref[Int] = Ref(0)
|
||||||
let captured_timestamp : Ref[UInt64] = Ref::new(0UL)
|
let captured_timestamp : Ref[UInt64] = Ref(0UL)
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
captured_target.val = rec.target
|
captured_target.val = rec.target
|
||||||
@@ -713,9 +713,9 @@ test "callback sink sees child target and context logger shape" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "bind aliases context fields ergonomically" {
|
test "bind aliases context fields ergonomically" {
|
||||||
let captured_target : Ref[String] = Ref::new("")
|
let captured_target : Ref[String] = Ref("")
|
||||||
let captured_message : Ref[String] = Ref::new("")
|
let captured_message : Ref[String] = Ref("")
|
||||||
let captured_fields : Ref[Array[Field]] = Ref::new([])
|
let captured_fields : Ref[Array[Field]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
captured_target.val = rec.target
|
captured_target.val = rec.target
|
||||||
@@ -738,7 +738,7 @@ test "bind aliases context fields ergonomically" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "buffered sink flushes manually" {
|
test "buffered sink flushes manually" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let sink = buffered_sink(
|
let sink = buffered_sink(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -758,7 +758,7 @@ test "buffered sink flushes manually" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "buffered sink flushes automatically at limit" {
|
test "buffered sink flushes automatically at limit" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let sink = buffered_sink(
|
let sink = buffered_sink(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -776,7 +776,7 @@ test "buffered sink flushes automatically at limit" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "filter sink only forwards matching records" {
|
test "filter sink only forwards matching records" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let sink = filter_sink(
|
let sink = filter_sink(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -796,7 +796,7 @@ test "filter sink only forwards matching records" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "logger with_filter composes naturally" {
|
test "logger with_filter composes naturally" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -814,7 +814,7 @@ test "logger with_filter composes naturally" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "filter helpers support target level and message composition" {
|
test "filter helpers support target level and message composition" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -834,7 +834,7 @@ test "filter helpers support target level and message composition" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "field helpers can match and negate records" {
|
test "field helpers can match and negate records" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -855,7 +855,7 @@ test "field helpers can match and negate records" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "any_of helper accepts multiple predicates" {
|
test "any_of helper accepts multiple predicates" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -875,9 +875,9 @@ test "any_of helper accepts multiple predicates" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "patch sink can rewrite message target and fields" {
|
test "patch sink can rewrite message target and fields" {
|
||||||
let captured_target : Ref[String] = Ref::new("")
|
let captured_target : Ref[String] = Ref("")
|
||||||
let captured_message : Ref[String] = Ref::new("")
|
let captured_message : Ref[String] = Ref("")
|
||||||
let captured_fields : Ref[Array[Field]] = Ref::new([])
|
let captured_fields : Ref[Array[Field]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
captured_target.val = rec.target
|
captured_target.val = rec.target
|
||||||
@@ -905,7 +905,7 @@ test "patch sink can rewrite message target and fields" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "patch helpers can redact multiple fields" {
|
test "patch helpers can redact multiple fields" {
|
||||||
let captured_fields : Ref[Array[Field]] = Ref::new([])
|
let captured_fields : Ref[Array[Field]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
captured_fields.val = rec.fields
|
captured_fields.val = rec.fields
|
||||||
@@ -924,7 +924,7 @@ test "patch helpers can redact multiple fields" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "queued sink drains in order" {
|
test "queued sink drains in order" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let sink = queued_sink(
|
let sink = queued_sink(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -947,7 +947,7 @@ test "queued sink drains in order" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "queued sink can drop newest when full" {
|
test "queued sink can drop newest when full" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let sink = queued_sink(
|
let sink = queued_sink(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -968,7 +968,7 @@ test "queued sink can drop newest when full" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "queued sink can drop oldest when full" {
|
test "queued sink can drop oldest when full" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let sink = queued_sink(
|
let sink = queued_sink(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
@@ -989,7 +989,7 @@ test "queued sink can drop oldest when full" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "logger with_queue preserves chaining ergonomics" {
|
test "logger with_queue preserves chaining ergonomics" {
|
||||||
let flushed_messages : Ref[Array[String]] = Ref::new([])
|
let flushed_messages : Ref[Array[String]] = Ref([])
|
||||||
let logger = Logger::new(
|
let logger = Logger::new(
|
||||||
callback_sink(fn(rec) {
|
callback_sink(fn(rec) {
|
||||||
flushed_messages.val.push(rec.message)
|
flushed_messages.val.push(rec.message)
|
||||||
|
|||||||
+1
-1
@@ -137,7 +137,7 @@ pub fn default_style_tag_registry() -> StyleTagRegistry {
|
|||||||
.set_tag("u", underline=true)
|
.set_tag("u", underline=true)
|
||||||
}
|
}
|
||||||
|
|
||||||
let global_style_tag_registry_ref : Ref[StyleTagRegistry] = Ref::new(style_tag_registry())
|
let global_style_tag_registry_ref : Ref[StyleTagRegistry] = Ref(style_tag_registry())
|
||||||
|
|
||||||
pub fn global_style_tag_registry() -> StyleTagRegistry {
|
pub fn global_style_tag_registry() -> StyleTagRegistry {
|
||||||
global_style_tag_registry_ref.val
|
global_style_tag_registry_ref.val
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
let default_console_sink : ConsoleSink = console_sink()
|
let default_console_sink : ConsoleSink = console_sink()
|
||||||
let default_min_level_ref : Ref[Level] = Ref::new(Level::Info)
|
let default_min_level_ref : Ref[Level] = Ref(Level::Info)
|
||||||
let default_target_ref : Ref[String] = Ref::new("")
|
let default_target_ref : Ref[String] = Ref("")
|
||||||
|
|
||||||
pub fn set_default_min_level(level : Level) -> Unit {
|
pub fn set_default_min_level(level : Level) -> Unit {
|
||||||
default_min_level_ref.val = level
|
default_min_level_ref.val = level
|
||||||
|
|||||||
+11
-11
@@ -138,18 +138,18 @@ pub fn file_sink(
|
|||||||
let handle = open_file_handle_internal(path, append)
|
let handle = open_file_handle_internal(path, append)
|
||||||
{
|
{
|
||||||
path,
|
path,
|
||||||
append: Ref::new(append),
|
append: Ref(append),
|
||||||
default_append: append,
|
default_append: append,
|
||||||
handle: Ref::new(handle),
|
handle: Ref(handle),
|
||||||
formatter,
|
formatter,
|
||||||
auto_flush: Ref::new(auto_flush),
|
auto_flush: Ref(auto_flush),
|
||||||
default_auto_flush: auto_flush,
|
default_auto_flush: auto_flush,
|
||||||
rotation: Ref::new(rotation),
|
rotation: Ref(rotation),
|
||||||
default_rotation: rotation,
|
default_rotation: rotation,
|
||||||
open_failures: Ref::new(if handle is Some(_) { 0 } else { 1 }),
|
open_failures: Ref(if handle is Some(_) { 0 } else { 1 }),
|
||||||
write_failures: Ref::new(0),
|
write_failures: Ref(0),
|
||||||
flush_failures: Ref::new(0),
|
flush_failures: Ref(0),
|
||||||
rotation_failures: Ref::new(0),
|
rotation_failures: Ref(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,7 +522,7 @@ pub struct BufferedSink[S] {
|
|||||||
|
|
||||||
pub fn[S] buffered_sink(sink : S, flush_limit~ : Int = 1) -> BufferedSink[S] {
|
pub fn[S] buffered_sink(sink : S, flush_limit~ : Int = 1) -> BufferedSink[S] {
|
||||||
let actual_limit = if flush_limit <= 0 { 1 } else { flush_limit }
|
let actual_limit = if flush_limit <= 0 { 1 } else { flush_limit }
|
||||||
{ sink, buffer: Ref::new([]), flush_limit: actual_limit }
|
{ sink, buffer: Ref([]), flush_limit: actual_limit }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn[S] BufferedSink::pending_count(self : BufferedSink[S]) -> Int {
|
pub fn[S] BufferedSink::pending_count(self : BufferedSink[S]) -> Int {
|
||||||
@@ -568,10 +568,10 @@ pub fn[S] queued_sink(
|
|||||||
) -> QueuedSink[S] {
|
) -> QueuedSink[S] {
|
||||||
{
|
{
|
||||||
sink,
|
sink,
|
||||||
queue: @queue.Queue::new(),
|
queue: @queue.Queue([]),
|
||||||
max_pending,
|
max_pending,
|
||||||
overflow,
|
overflow,
|
||||||
dropped_count: Ref::new(0),
|
dropped_count: Ref(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user