Skip to content

Commit cfce307

Browse files
committed
refactor(app): replace print statements with logging in AppStatusService
- Add logging dependency to app_status_service.dart - Replace print statements with _logger.info() calls - Add _logger field to AppStatusService class - Update log messages to use logger instead of print
1 parent 7159eae commit cfce307

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/app/services/app_status_service.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44
import 'package:flutter_bloc/flutter_bloc.dart';
55
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
66
import 'package:flutter_news_app_mobile_client_full_source_code/app/config/config.dart';
7+
import 'package:logging/logging.dart';
78

89
/// {@template app_status_service}
910
/// A service dedicated to monitoring the application's lifecycle and
@@ -32,7 +33,8 @@ class AppStatusService with WidgetsBindingObserver {
3233
required AppEnvironment environment,
3334
}) : _context = context,
3435
_checkInterval = checkInterval,
35-
_environment = environment {
36+
_environment = environment,
37+
_logger = Logger('AppStatusService') {
3638
// Immediately register this service as a lifecycle observer.
3739
WidgetsBinding.instance.addObserver(this);
3840
// Start the periodic checks.
@@ -48,6 +50,9 @@ class AppStatusService with WidgetsBindingObserver {
4850
/// The current application environment.
4951
final AppEnvironment _environment;
5052

53+
/// The logger instance for this service.
54+
final Logger _logger;
55+
5156
/// The timer responsible for periodic checks.
5257
Timer? _timer;
5358

@@ -62,10 +67,10 @@ class AppStatusService with WidgetsBindingObserver {
6267
_timer = Timer.periodic(_checkInterval, (_) {
6368
// In demo mode, periodic checks are not needed as there's no backend.
6469
if (_environment == AppEnvironment.demo) {
65-
print('[AppStatusService] Demo mode: Skipping periodic check.');
70+
_logger.info('[AppStatusService] Demo mode: Skipping periodic check.');
6671
return;
6772
}
68-
print(
73+
_logger.info(
6974
'[AppStatusService] Periodic check triggered. Requesting AppConfig fetch.',
7075
);
7176
// Add the event to the AppBloc to fetch the latest config.
@@ -84,13 +89,13 @@ class AppStatusService with WidgetsBindingObserver {
8489
// useful on web, where switching browser tabs would otherwise trigger
8590
// a reload, which is unnecessary and can be distracting for demos.
8691
if (_environment == AppEnvironment.demo) {
87-
print('[AppStatusService] Demo mode: Skipping app lifecycle check.');
92+
_logger.info('[AppStatusService] Demo mode: Skipping app lifecycle check.');
8893
return;
8994
}
9095

9196
// We are only interested in the 'resumed' state.
9297
if (state == AppLifecycleState.resumed) {
93-
print('[AppStatusService] App resumed. Requesting AppConfig fetch.');
98+
_logger.info('[AppStatusService] App resumed. Requesting AppConfig fetch.');
9499
// When the app comes to the foreground, immediately trigger a check.
95100
// This is crucial for catching maintenance mode that was enabled
96101
// while the app was in the background.
@@ -106,7 +111,7 @@ class AppStatusService with WidgetsBindingObserver {
106111
/// the main app widget is disposed) to prevent memory leaks from the
107112
/// timer and the observer registration.
108113
void dispose() {
109-
print('[AppStatusService] Disposing service.');
114+
_logger.info('[AppStatusService] Disposing service.');
110115
// Stop the periodic timer.
111116
_timer?.cancel();
112117
// Remove this object from the list of lifecycle observers.

0 commit comments

Comments
 (0)