mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-31 07:24:31 +00:00
🧹 apply moon fmt and async mbti refresh
This commit is contained in:
@@ -190,7 +190,7 @@ async test "run rejects duplicate worker startup for same logger" {
|
|||||||
@async.pause()
|
@async.pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
let second_error = (async fn() -> String raise {
|
let second_error = (async fn() -> String {
|
||||||
logger.run()
|
logger.run()
|
||||||
"no error"
|
"no error"
|
||||||
})() catch {
|
})() catch {
|
||||||
|
|||||||
@@ -180,9 +180,9 @@ pub fn[S] async_logger(
|
|||||||
///|
|
///|
|
||||||
fn async_logger_phase_is_closed(phase : AsyncLifecyclePhase) -> Bool {
|
fn async_logger_phase_is_closed(phase : AsyncLifecyclePhase) -> Bool {
|
||||||
match phase {
|
match phase {
|
||||||
AsyncLifecyclePhase::Closing |
|
AsyncLifecyclePhase::Closing
|
||||||
AsyncLifecyclePhase::Closed |
|
| AsyncLifecyclePhase::Closed
|
||||||
AsyncLifecyclePhase::ClosedFailed => true
|
| AsyncLifecyclePhase::ClosedFailed => true
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
package "Nanaloveyuki/BitLogger/src-async"
|
package "Nanaloveyuki/BitLogger/src-async"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
"Nanaloveyuki/BitLogger/src",
|
|
||||||
"Nanaloveyuki/BitLogger/src-async/utils",
|
"Nanaloveyuki/BitLogger/src-async/utils",
|
||||||
"Nanaloveyuki/BitLogger/src/core",
|
"Nanaloveyuki/BitLogger/src/core",
|
||||||
|
"Nanaloveyuki/BitLogger/src/runtime",
|
||||||
|
"Nanaloveyuki/BitLogger/src/sink_graph",
|
||||||
"maria/json_parser",
|
"maria/json_parser",
|
||||||
"moonbitlang/async/aqueue",
|
"moonbitlang/async/aqueue",
|
||||||
"moonbitlang/core/ref",
|
"moonbitlang/core/ref",
|
||||||
@@ -29,21 +30,21 @@ pub fn async_runtime_state_to_json(@utils.AsyncRuntimeState) -> @json_parser.Jso
|
|||||||
|
|
||||||
pub fn async_runtime_supports_background_worker() -> Bool
|
pub fn async_runtime_supports_background_worker() -> Bool
|
||||||
|
|
||||||
pub fn build_application_async_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@src.RuntimeSink]
|
pub fn build_application_async_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@runtime.RuntimeSink]
|
||||||
|
|
||||||
pub fn build_application_text_async_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@src.FormattedConsoleSink]
|
pub fn build_application_text_async_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@sink_graph.FormattedConsoleSink]
|
||||||
|
|
||||||
pub fn build_async_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@src.RuntimeSink]
|
pub fn build_async_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@runtime.RuntimeSink]
|
||||||
|
|
||||||
pub fn build_async_text_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@src.FormattedConsoleSink]
|
pub fn build_async_text_logger(@utils.AsyncLoggerBuildConfig) -> AsyncLogger[@sink_graph.FormattedConsoleSink]
|
||||||
|
|
||||||
pub fn build_library_async_logger(@utils.AsyncLoggerBuildConfig) -> LibraryAsyncLogger[@src.RuntimeSink]
|
pub fn build_library_async_logger(@utils.AsyncLoggerBuildConfig) -> LibraryAsyncLogger[@runtime.RuntimeSink]
|
||||||
|
|
||||||
pub fn build_library_async_text_logger(@utils.AsyncLoggerBuildConfig) -> LibraryAsyncLogger[@src.FormattedConsoleSink]
|
pub fn build_library_async_text_logger(@utils.AsyncLoggerBuildConfig) -> LibraryAsyncLogger[@sink_graph.FormattedConsoleSink]
|
||||||
|
|
||||||
pub fn parse_and_build_application_async_logger(String) -> AsyncLogger[@src.RuntimeSink] raise
|
pub fn parse_and_build_application_async_logger(String) -> AsyncLogger[@runtime.RuntimeSink] raise
|
||||||
|
|
||||||
pub fn parse_and_build_library_async_logger(String) -> LibraryAsyncLogger[@src.RuntimeSink] raise
|
pub fn parse_and_build_library_async_logger(String) -> LibraryAsyncLogger[@runtime.RuntimeSink] raise
|
||||||
|
|
||||||
pub fn parse_async_logger_build_config_text(String) -> @utils.AsyncLoggerBuildConfig raise
|
pub fn parse_async_logger_build_config_text(String) -> @utils.AsyncLoggerBuildConfig raise
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ pub fn[S] AsyncLogger::last_error(Self[S]) -> String
|
|||||||
pub async fn[S] AsyncLogger::log(Self[S], @core.Level, String, fields? : Array[@core.Field], target? : String) -> Unit
|
pub async fn[S] AsyncLogger::log(Self[S], @core.Level, String, fields? : Array[@core.Field], target? : String) -> Unit
|
||||||
pub fn[S] AsyncLogger::pending_count(Self[S]) -> Int
|
pub fn[S] AsyncLogger::pending_count(Self[S]) -> Int
|
||||||
pub fn[S] AsyncLogger::phase(Self[S]) -> @utils.AsyncLifecyclePhase
|
pub fn[S] AsyncLogger::phase(Self[S]) -> @utils.AsyncLifecyclePhase
|
||||||
pub async fn[S : @src.Sink] AsyncLogger::run(Self[S]) -> Unit
|
pub async fn[S : @sink_graph.Sink] AsyncLogger::run(Self[S]) -> Unit
|
||||||
pub async fn[S] AsyncLogger::shutdown(Self[S], clear? : Bool) -> Unit
|
pub async fn[S] AsyncLogger::shutdown(Self[S], clear? : Bool) -> Unit
|
||||||
pub fn[S] AsyncLogger::state(Self[S]) -> @utils.AsyncLoggerState
|
pub fn[S] AsyncLogger::state(Self[S]) -> @utils.AsyncLoggerState
|
||||||
pub fn[S] AsyncLogger::to_library_async_logger(Self[S]) -> LibraryAsyncLogger[S]
|
pub fn[S] AsyncLogger::to_library_async_logger(Self[S]) -> LibraryAsyncLogger[S]
|
||||||
@@ -125,7 +126,7 @@ pub async fn[S] LibraryAsyncLogger::info(Self[S], String, fields? : Array[@core.
|
|||||||
pub fn[S] LibraryAsyncLogger::is_enabled(Self[S], @core.Level) -> Bool
|
pub fn[S] LibraryAsyncLogger::is_enabled(Self[S], @core.Level) -> Bool
|
||||||
pub async fn[S] LibraryAsyncLogger::log(Self[S], @core.Level, String, fields? : Array[@core.Field], target? : String) -> Unit
|
pub async fn[S] LibraryAsyncLogger::log(Self[S], @core.Level, String, fields? : Array[@core.Field], target? : String) -> Unit
|
||||||
pub fn[S] LibraryAsyncLogger::new(S, config? : @utils.AsyncLoggerConfig, min_level? : @core.Level, target? : String, flush? : (S) -> Unit raise) -> Self[S]
|
pub fn[S] LibraryAsyncLogger::new(S, config? : @utils.AsyncLoggerConfig, min_level? : @core.Level, target? : String, flush? : (S) -> Unit raise) -> Self[S]
|
||||||
pub async fn[S : @src.Sink] LibraryAsyncLogger::run(Self[S]) -> Unit
|
pub async fn[S : @sink_graph.Sink] LibraryAsyncLogger::run(Self[S]) -> Unit
|
||||||
pub async fn[S] LibraryAsyncLogger::shutdown(Self[S], clear? : Bool) -> Unit
|
pub async fn[S] LibraryAsyncLogger::shutdown(Self[S], clear? : Bool) -> Unit
|
||||||
pub fn[S] LibraryAsyncLogger::to_async_logger(Self[S]) -> AsyncLogger[S]
|
pub fn[S] LibraryAsyncLogger::to_async_logger(Self[S]) -> AsyncLogger[S]
|
||||||
pub async fn[S] LibraryAsyncLogger::warn(Self[S], String, fields? : Array[@core.Field]) -> Unit
|
pub async fn[S] LibraryAsyncLogger::warn(Self[S], String, fields? : Array[@core.Field]) -> Unit
|
||||||
@@ -133,9 +134,9 @@ pub fn[S] LibraryAsyncLogger::with_context_fields(Self[S], Array[@core.Field]) -
|
|||||||
pub fn[S] LibraryAsyncLogger::with_target(Self[S], String) -> Self[S]
|
pub fn[S] LibraryAsyncLogger::with_target(Self[S], String) -> Self[S]
|
||||||
|
|
||||||
// Type aliases
|
// Type aliases
|
||||||
pub type ApplicationAsyncLogger = AsyncLogger[@src.RuntimeSink]
|
pub type ApplicationAsyncLogger = AsyncLogger[@runtime.RuntimeSink]
|
||||||
|
|
||||||
pub type ApplicationTextAsyncLogger = AsyncLogger[@src.FormattedConsoleSink]
|
pub type ApplicationTextAsyncLogger = AsyncLogger[@sink_graph.FormattedConsoleSink]
|
||||||
|
|
||||||
pub using @utils {type AsyncFlushPolicy}
|
pub using @utils {type AsyncFlushPolicy}
|
||||||
|
|
||||||
|
|||||||
@@ -75,9 +75,9 @@ fn async_lifecycle_phase_label(phase : AsyncLifecyclePhase) -> String {
|
|||||||
///|
|
///|
|
||||||
fn async_lifecycle_phase_is_closed(phase : AsyncLifecyclePhase) -> Bool {
|
fn async_lifecycle_phase_is_closed(phase : AsyncLifecyclePhase) -> Bool {
|
||||||
match phase {
|
match phase {
|
||||||
AsyncLifecyclePhase::Closing |
|
AsyncLifecyclePhase::Closing
|
||||||
AsyncLifecyclePhase::Closed |
|
| AsyncLifecyclePhase::Closed
|
||||||
AsyncLifecyclePhase::ClosedFailed => true
|
| AsyncLifecyclePhase::ClosedFailed => true
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,9 +203,7 @@ fn async_logger_state_to_json_value(
|
|||||||
"is_closed": @json_parser.JsonValue::Bool(state.is_closed),
|
"is_closed": @json_parser.JsonValue::Bool(state.is_closed),
|
||||||
"is_running": @json_parser.JsonValue::Bool(state.is_running),
|
"is_running": @json_parser.JsonValue::Bool(state.is_running),
|
||||||
"has_failed": @json_parser.JsonValue::Bool(state.has_failed),
|
"has_failed": @json_parser.JsonValue::Bool(state.has_failed),
|
||||||
"backlog_retained": @json_parser.JsonValue::Bool(
|
"backlog_retained": @json_parser.JsonValue::Bool(state.backlog_retained),
|
||||||
state.backlog_retained,
|
|
||||||
),
|
|
||||||
"can_rerun": @json_parser.JsonValue::Bool(state.can_rerun),
|
"can_rerun": @json_parser.JsonValue::Bool(state.can_rerun),
|
||||||
"terminal": @json_parser.JsonValue::Bool(state.terminal),
|
"terminal": @json_parser.JsonValue::Bool(state.terminal),
|
||||||
"last_error": @json_parser.JsonValue::String(state.last_error),
|
"last_error": @json_parser.JsonValue::String(state.last_error),
|
||||||
|
|||||||
@@ -128,9 +128,7 @@ pub fn Logger::file_rotation_failures(self : Logger[RuntimeSink]) -> Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
pub fn Logger::file_reset_failure_counters(
|
pub fn Logger::file_reset_failure_counters(self : Logger[RuntimeSink]) -> Bool {
|
||||||
self : Logger[RuntimeSink],
|
|
||||||
) -> Bool {
|
|
||||||
@runtime.RuntimeSink::file_reset_failure_counters(self.sink)
|
@runtime.RuntimeSink::file_reset_failure_counters(self.sink)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,16 +164,12 @@ pub fn Logger::file_default_policy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
pub fn Logger::file_policy_matches_default(
|
pub fn Logger::file_policy_matches_default(self : Logger[RuntimeSink]) -> Bool {
|
||||||
self : Logger[RuntimeSink],
|
|
||||||
) -> Bool {
|
|
||||||
@runtime.RuntimeSink::file_policy_matches_default(self.sink)
|
@runtime.RuntimeSink::file_policy_matches_default(self.sink)
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
pub fn Logger::file_state_or_none(
|
pub fn Logger::file_state_or_none(self : Logger[RuntimeSink]) -> FileSinkState? {
|
||||||
self : Logger[RuntimeSink],
|
|
||||||
) -> FileSinkState? {
|
|
||||||
@runtime.RuntimeSink::file_state_or_none(self.sink)
|
@runtime.RuntimeSink::file_state_or_none(self.sink)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,7 @@ pub fn Logger::drain_progress(
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
pub fn Logger::drain(
|
pub fn Logger::drain(self : Logger[RuntimeSink], max_items? : Int = -1) -> Int {
|
||||||
self : Logger[RuntimeSink],
|
|
||||||
max_items? : Int = -1,
|
|
||||||
) -> Int {
|
|
||||||
@runtime.RuntimeSink::drain(self.sink, max_items~)
|
@runtime.RuntimeSink::drain(self.sink, max_items~)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
///|
|
///|
|
||||||
test "text formatter can customize visible parts" {
|
test "text formatter can customize visible parts" {
|
||||||
let rec = Record::new(Level::Info, "hello", timestamp_ms=123UL, target="svc.api", fields=[
|
let rec = Record::new(
|
||||||
field("user", "alice"),
|
Level::Info,
|
||||||
field("request_id", "42"),
|
"hello",
|
||||||
])
|
timestamp_ms=123UL,
|
||||||
|
target="svc.api",
|
||||||
|
fields=[field("user", "alice"), field("request_id", "42")],
|
||||||
|
)
|
||||||
let compact = text_formatter(
|
let compact = text_formatter(
|
||||||
show_timestamp=false,
|
show_timestamp=false,
|
||||||
show_target=false,
|
show_target=false,
|
||||||
@@ -458,9 +461,13 @@ test "formatted callback sink receives rendered text" {
|
|||||||
|
|
||||||
///|
|
///|
|
||||||
test "json formatter keeps structured shape" {
|
test "json formatter keeps structured shape" {
|
||||||
let rec = Record::new(Level::Error, "failed", timestamp_ms=55UL, target="svc", fields=[
|
let rec = Record::new(
|
||||||
field("code", "500"),
|
Level::Error,
|
||||||
])
|
"failed",
|
||||||
|
timestamp_ms=55UL,
|
||||||
|
target="svc",
|
||||||
|
fields=[field("code", "500")],
|
||||||
|
)
|
||||||
inspect(
|
inspect(
|
||||||
format_json(rec),
|
format_json(rec),
|
||||||
content="{\"level\":\"ERROR\",\"message\":\"failed\",\"fields\":{\"code\":\"500\"},\"timestamp_ms\":\"55\",\"target\":\"svc\"}",
|
content="{\"level\":\"ERROR\",\"message\":\"failed\",\"fields\":{\"code\":\"500\"},\"timestamp_ms\":\"55\",\"target\":\"svc\"}",
|
||||||
|
|||||||
Reference in New Issue
Block a user