Skip to content

Commit 48b1da6

Browse files
committed
refactor(bootstrap): improve logger usage and code readability
- Chaining logger methods for better readability - Removing unnecessary print statement - Consistent use of string interpolation - Removing extra empty lines
1 parent dd2ef00 commit 48b1da6

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

lib/bootstrap.dart

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Future<Widget> bootstrap(
4343
Logger.root.level = environment == app_config.AppEnvironment.production
4444
? Level.INFO
4545
: Level.ALL;
46-
46+
4747
Logger.root.onRecord.listen((record) {
4848
final message = StringBuffer(
4949
'${record.level.name}: ${record.time}: ${record.loggerName}: ${record.message}',
@@ -54,12 +54,12 @@ Future<Widget> bootstrap(
5454
if (record.stackTrace != null) {
5555
message.write('\nStack Trace: ${record.stackTrace}');
5656
}
57-
print(message.toString());
57+
print(message);
5858
});
5959

60-
final logger = Logger('bootstrap');
61-
logger.config('--- Starting Bootstrap Process ---');
62-
logger.config('App Environment: $environment');
60+
final logger = Logger('bootstrap')
61+
..config('--- Starting Bootstrap Process ---')
62+
..config('App Environment: $environment');
6363

6464
WidgetsFlutterBinding.ensureInitialized();
6565
Bloc.observer = const AppBlocObserver();
@@ -86,10 +86,10 @@ Future<Widget> bootstrap(
8686
kvStorage.readString(key: StorageKey.authToken.stringValue),
8787
logger: logger,
8888
);
89-
logger.fine('HttpClient initialized for base URL: ${appConfig.baseUrl}');
90-
91-
// 3. Initialize RemoteConfigClient and Repository, and fetch RemoteConfig.
92-
logger.info('3. Initializing RemoteConfig client and repository...');
89+
logger
90+
..fine('HttpClient initialized for base URL: ${appConfig.baseUrl}')
91+
// 3. Initialize RemoteConfigClient and Repository, and fetch RemoteConfig.
92+
..info('3. Initializing RemoteConfig client and repository...');
9393
// This is done early because RemoteConfig is now publicly accessible (unauthenticated).
9494
late DataClient<RemoteConfig> remoteConfigClient;
9595
if (appConfig.environment == app_config.AppEnvironment.demo) {
@@ -159,10 +159,10 @@ Future<Widget> bootstrap(
159159
storageService: kvStorage,
160160
);
161161
}
162-
logger.fine('Authentication repository initialized.');
163-
164-
// 5. Initialize AdProvider and AdService.
165-
logger.info('6. Initializing Ad providers and AdService...');
162+
logger
163+
..fine('Authentication repository initialized.')
164+
// 5. Initialize AdProvider and AdService.
165+
..info('6. Initializing Ad providers and AdService...');
166166
late final Map<AdPlatformType, AdProvider> adProviders;
167167

168168
// Conditionally instantiate ad providers based on the application environment.
@@ -215,11 +215,11 @@ Future<Widget> bootstrap(
215215

216216
// Initialize InlineAdCacheService with the created AdService.
217217
inlineAdCacheService = InlineAdCacheService(adService: adService);
218-
logger.fine('InlineAdCacheService initialized.');
219-
220-
// Fetch the initial user from the authentication repository.
221-
// This ensures the AppBloc starts with an accurate authentication status.
222-
logger.info('7. Fetching initial user...');
218+
logger
219+
..fine('InlineAdCacheService initialized.')
220+
// Fetch the initial user from the authentication repository.
221+
// This ensures the AppBloc starts with an accurate authentication status.
222+
..info('7. Fetching initial user...');
223223
final initialUser = await authenticationRepository.getCurrentUser();
224224
logger.fine('Initial user fetched: ${initialUser?.id ?? 'none'}.');
225225

@@ -229,10 +229,10 @@ Future<Widget> bootstrap(
229229

230230
// Initialize PackageInfoService
231231
final packageInfoService = PackageInfoServiceImpl(logger: logger);
232-
logger.fine('PackageInfoService initialized.');
233-
234-
// 6. Initialize all other DataClients and Repositories.
235-
logger.info('8. Initializing Data clients and repositories...');
232+
logger
233+
..fine('PackageInfoService initialized.')
234+
// 6. Initialize all other DataClients and Repositories.
235+
..info('8. Initializing Data clients and repositories...');
236236
// These now also have a guaranteed valid httpClient.
237237
late final DataClient<Headline> headlinesClient;
238238
late final DataClient<Topic> topicsClient;
@@ -480,11 +480,11 @@ Future<Widget> bootstrap(
480480
userContentPreferencesRepository: userContentPreferencesRepository,
481481
)
482482
: null;
483-
logger.fine(
484-
'DemoDataInitializerService initialized: ${demoDataInitializerService != null}',
485-
);
486-
487-
logger.info('--- Bootstrap Process Complete. Returning App widget. ---');
483+
logger
484+
..fine(
485+
'DemoDataInitializerService initialized: ${demoDataInitializerService != null}',
486+
)
487+
..info('--- Bootstrap Process Complete. Returning App widget. ---');
488488
return App(
489489
authenticationRepository: authenticationRepository,
490490
headlinesRepository: headlinesRepository,

0 commit comments

Comments
 (0)