Skip to content

Commit f769493

Browse files
committed
fix(api): restore root logger configuration in middleware
Re-introduces the root logger configuration, which was lost during the refactor away from `lib/server.dart`. The configuration is now placed in the root middleware and uses a flag to ensure it only runs once per application lifecycle. This is critical for enabling log output for all subsequent processes, including dependency initialization and error handling.
1 parent dd394d9 commit f769493

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

routes/_middleware.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,29 @@ class RequestId {
5959
// --- Middleware Definition ---
6060
final _log = Logger('RootMiddleware');
6161

62+
// A flag to ensure the logger is only configured once for the application's
63+
// entire lifecycle.
64+
bool _loggerConfigured = false;
65+
6266
Handler middleware(Handler handler) {
6367
// This is the root middleware for the entire API. It's responsible for
6468
// providing all shared dependencies to the request context.
6569
// The order of `.use()` calls is important: the last one in the chain
6670
// runs first.
71+
72+
// This check ensures that the logger is configured only once.
73+
if (!_loggerConfigured) {
74+
Logger.root.level = Level.ALL;
75+
Logger.root.onRecord.listen((record) {
76+
// ignore: avoid_print
77+
print(
78+
'${record.level.name}: ${record.time}: ${record.loggerName}: '
79+
'${record.message}',
80+
);
81+
});
82+
_loggerConfigured = true;
83+
}
84+
6785
return handler
6886
// --- Core Middleware ---
6987
// These run after all dependencies have been provided.

0 commit comments

Comments
 (0)