Add native async logger adapter package

This commit is contained in:
Nanaloveyuki
2026-05-08 17:28:37 +08:00
parent 9a0d7abd8e
commit a99d2658f4
8 changed files with 371 additions and 10 deletions
+7 -7
View File
@@ -32,28 +32,28 @@ fn string_to_c_bytes(str : String) -> Bytes {
}
#external
priv type NativeFileHandle
type NativeFileHandle
#borrow(path, mode)
extern "c" fn file_open_ffi(path : Bytes, mode : Bytes) -> NativeFileHandle = "fopen"
extern "C" fn file_open_ffi(path : Bytes, mode : Bytes) -> NativeFileHandle = "fopen"
extern "c" fn file_is_null_ffi(handle : NativeFileHandle) -> Bool = "%null?"
extern "C" fn file_is_null_ffi(handle : NativeFileHandle) -> Bool = "moonbitlang_async_pointer_is_null"
#borrow(buffer)
extern "c" fn file_write_ffi(
extern "C" fn file_write_ffi(
buffer : Bytes,
size : Int,
count : Int,
handle : NativeFileHandle,
) -> Int = "fwrite"
extern "c" fn file_flush_ffi(handle : NativeFileHandle) -> Int = "fflush"
extern "C" fn file_flush_ffi(handle : NativeFileHandle) -> Int = "fflush"
extern "c" fn file_close_ffi(handle : NativeFileHandle) -> Int = "fclose"
extern "C" fn file_close_ffi(handle : NativeFileHandle) -> Int = "fclose"
pub struct FileHandle {
raw : NativeFileHandle
path : String
raw : NativeFileHandle
}
fn open_file_handle_internal(path : String, append : Bool) -> FileHandle? {
+11 -1
View File
@@ -15,7 +15,7 @@ pub struct Record {
fields : Array[Field]
}
fn record(
pub fn Record::new(
level : Level,
message : String,
timestamp_ms~ : UInt64 = 0UL,
@@ -24,3 +24,13 @@ fn record(
) -> Record {
{ level, timestamp_ms, target, message, fields }
}
fn record(
level : Level,
message : String,
timestamp_ms~ : UInt64 = 0UL,
target~ : String = "",
fields~ : Array[Field] = [],
) -> Record {
Record::new(level, message, timestamp_ms=timestamp_ms, target=target, fields=fields)
}