From 74b9815babd599063f947015ab07d9e6ce01366f Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Wed, 8 Jul 2026 12:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20apply=20moon=20fmt=20and=20async?= =?UTF-8?q?=20mbti=20refresh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-async/BitLoggerAsync_test.mbt | 2 +- src-async/async_logger_shared.mbt | 6 +++--- src-async/pkg.generated.mbti | 27 ++++++++++++++------------- src-async/utils/async_models.mbt | 10 ++++------ src/runtime_file_controls.mbt | 12 +++--------- src/runtime_logger.mbt | 5 +---- src/text_formatter_test.mbt | 21 ++++++++++++++------- 7 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src-async/BitLoggerAsync_test.mbt b/src-async/BitLoggerAsync_test.mbt index 0f30749..dd08ed1 100644 --- a/src-async/BitLoggerAsync_test.mbt +++ b/src-async/BitLoggerAsync_test.mbt @@ -190,7 +190,7 @@ async test "run rejects duplicate worker startup for same logger" { @async.pause() } - let second_error = (async fn() -> String raise { + let second_error = (async fn() -> String { logger.run() "no error" })() catch { diff --git a/src-async/async_logger_shared.mbt b/src-async/async_logger_shared.mbt index 436605c..01827ca 100644 --- a/src-async/async_logger_shared.mbt +++ b/src-async/async_logger_shared.mbt @@ -180,9 +180,9 @@ pub fn[S] async_logger( ///| fn async_logger_phase_is_closed(phase : AsyncLifecyclePhase) -> Bool { match phase { - AsyncLifecyclePhase::Closing | - AsyncLifecyclePhase::Closed | - AsyncLifecyclePhase::ClosedFailed => true + AsyncLifecyclePhase::Closing + | AsyncLifecyclePhase::Closed + | AsyncLifecyclePhase::ClosedFailed => true _ => false } } diff --git a/src-async/pkg.generated.mbti b/src-async/pkg.generated.mbti index 50c0960..f50601a 100644 --- a/src-async/pkg.generated.mbti +++ b/src-async/pkg.generated.mbti @@ -2,9 +2,10 @@ package "Nanaloveyuki/BitLogger/src-async" import { - "Nanaloveyuki/BitLogger/src", "Nanaloveyuki/BitLogger/src-async/utils", "Nanaloveyuki/BitLogger/src/core", + "Nanaloveyuki/BitLogger/src/runtime", + "Nanaloveyuki/BitLogger/src/sink_graph", "maria/json_parser", "moonbitlang/async/aqueue", "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 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 @@ -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 fn[S] AsyncLogger::pending_count(Self[S]) -> Int 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 fn[S] AsyncLogger::state(Self[S]) -> @utils.AsyncLoggerState 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 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 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 fn[S] LibraryAsyncLogger::to_async_logger(Self[S]) -> AsyncLogger[S] 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] // 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} diff --git a/src-async/utils/async_models.mbt b/src-async/utils/async_models.mbt index 5dd1b5b..395f8f0 100644 --- a/src-async/utils/async_models.mbt +++ b/src-async/utils/async_models.mbt @@ -75,9 +75,9 @@ fn async_lifecycle_phase_label(phase : AsyncLifecyclePhase) -> String { ///| fn async_lifecycle_phase_is_closed(phase : AsyncLifecyclePhase) -> Bool { match phase { - AsyncLifecyclePhase::Closing | - AsyncLifecyclePhase::Closed | - AsyncLifecyclePhase::ClosedFailed => true + AsyncLifecyclePhase::Closing + | AsyncLifecyclePhase::Closed + | AsyncLifecyclePhase::ClosedFailed => true _ => false } } @@ -203,9 +203,7 @@ fn async_logger_state_to_json_value( "is_closed": @json_parser.JsonValue::Bool(state.is_closed), "is_running": @json_parser.JsonValue::Bool(state.is_running), "has_failed": @json_parser.JsonValue::Bool(state.has_failed), - "backlog_retained": @json_parser.JsonValue::Bool( - state.backlog_retained, - ), + "backlog_retained": @json_parser.JsonValue::Bool(state.backlog_retained), "can_rerun": @json_parser.JsonValue::Bool(state.can_rerun), "terminal": @json_parser.JsonValue::Bool(state.terminal), "last_error": @json_parser.JsonValue::String(state.last_error), diff --git a/src/runtime_file_controls.mbt b/src/runtime_file_controls.mbt index dbf7752..04ced0e 100644 --- a/src/runtime_file_controls.mbt +++ b/src/runtime_file_controls.mbt @@ -128,9 +128,7 @@ pub fn Logger::file_rotation_failures(self : Logger[RuntimeSink]) -> Int { } ///| -pub fn Logger::file_reset_failure_counters( - self : Logger[RuntimeSink], -) -> Bool { +pub fn Logger::file_reset_failure_counters(self : Logger[RuntimeSink]) -> Bool { @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( - self : Logger[RuntimeSink], -) -> Bool { +pub fn Logger::file_policy_matches_default(self : Logger[RuntimeSink]) -> Bool { @runtime.RuntimeSink::file_policy_matches_default(self.sink) } ///| -pub fn Logger::file_state_or_none( - self : Logger[RuntimeSink], -) -> FileSinkState? { +pub fn Logger::file_state_or_none(self : Logger[RuntimeSink]) -> FileSinkState? { @runtime.RuntimeSink::file_state_or_none(self.sink) } diff --git a/src/runtime_logger.mbt b/src/runtime_logger.mbt index 6d8b9d6..dd5f499 100644 --- a/src/runtime_logger.mbt +++ b/src/runtime_logger.mbt @@ -46,10 +46,7 @@ pub fn Logger::drain_progress( } ///| -pub fn Logger::drain( - self : Logger[RuntimeSink], - max_items? : Int = -1, -) -> Int { +pub fn Logger::drain(self : Logger[RuntimeSink], max_items? : Int = -1) -> Int { @runtime.RuntimeSink::drain(self.sink, max_items~) } diff --git a/src/text_formatter_test.mbt b/src/text_formatter_test.mbt index 36e21c7..3e7aa83 100644 --- a/src/text_formatter_test.mbt +++ b/src/text_formatter_test.mbt @@ -1,9 +1,12 @@ ///| test "text formatter can customize visible parts" { - let rec = Record::new(Level::Info, "hello", timestamp_ms=123UL, target="svc.api", fields=[ - field("user", "alice"), - field("request_id", "42"), - ]) + let rec = Record::new( + Level::Info, + "hello", + timestamp_ms=123UL, + target="svc.api", + fields=[field("user", "alice"), field("request_id", "42")], + ) let compact = text_formatter( show_timestamp=false, show_target=false, @@ -458,9 +461,13 @@ test "formatted callback sink receives rendered text" { ///| test "json formatter keeps structured shape" { - let rec = Record::new(Level::Error, "failed", timestamp_ms=55UL, target="svc", fields=[ - field("code", "500"), - ]) + let rec = Record::new( + Level::Error, + "failed", + timestamp_ms=55UL, + target="svc", + fields=[field("code", "500")], + ) inspect( format_json(rec), content="{\"level\":\"ERROR\",\"message\":\"failed\",\"fields\":{\"code\":\"500\"},\"timestamp_ms\":\"55\",\"target\":\"svc\"}",