Skip to content

Commit

Permalink
#355: fixed not all logs showing
Browse files Browse the repository at this point in the history
  • Loading branch information
jorre127 committed Oct 15, 2024
1 parent 7ad2eec commit 02686c9
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 304 deletions.
7 changes: 2 additions & 5 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import 'package:flutter_template/di/injectable.dart';
import 'package:flutter_template/navigator/main_navigator.dart';
import 'package:flutter_template/styles/theme_data.dart';
import 'package:flutter_template/util/locale/localization_fallback_cupertino_delegate.dart';
import 'package:flutter_template/util/logging_util.dart';
import 'package:flutter_template/viewmodel/global/global_viewmodel.dart';
import 'package:flutter_template/widget/general/flavor_banner.dart';
import 'package:flutter_template/widget/general/text_scale_factor.dart';
import 'package:flutter_template/widget/provider/provider_widget.dart';
import 'package:icapps_architecture/icapps_architecture.dart';
import 'package:log_to_secure_file/log_to_secure_file.dart';

class MyApp extends StatelessWidget {
const MyApp({super.key});
Expand All @@ -27,9 +26,7 @@ class MyApp extends StatelessWidget {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);

// init logger
final fileLogger = getIt.get<SecureLogStorage>();
fileLogger.init();
LoggingFactory.configure(LoggingConfiguration(onLog: (value) => fileLogger.storeLogLine(value)));
LoggingUtil.startLogging();

return const InternalApp();
}
Expand Down
16 changes: 16 additions & 0 deletions lib/util/logging_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter_template/di/injectable.dart';
import 'package:icapps_architecture/icapps_architecture.dart';
import 'package:log_to_secure_file/log_to_secure_file.dart';
import 'package:synchronized/synchronized.dart';

class LoggingUtil {
static final _loggerLock = Lock();

static void startLogging() {
final fileLogger = getIt.get<SecureLogStorage>();
fileLogger.init();
LoggingFactory.configure(LoggingConfiguration(onLog: (value) => storeLogLine(value)));
}

static void storeLogLine(String line) => _loggerLock.synchronized(() => getIt.get<SecureLogStorage>().storeLogLine(line));
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies:
sprintf: ^7.0.0
sqlite3_flutter_libs: ^0.5.12
storage_inspector: ^0.4.0
synchronized: ^3.0.1
synchronized: ^3.3.0+3
url_launcher: ^6.3.1

dev_dependencies:
Expand Down
91 changes: 55 additions & 36 deletions test/util/test_util.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import 'dart:async' as _i5;
import 'dart:ui' as _i4;

import 'package:drift/drift.dart' as _i11;
import 'package:flutter/material.dart' as _i1;
import 'package:flutter/material.dart' as _i2;
import 'package:flutter_template/model/snackbar/snackbar_data.dart' as _i12;
import 'package:flutter_template/navigator/main_navigator.dart' as _i10;
import 'package:flutter_template/util/locale/localization.dart' as _i7;
import 'package:flutter_template/util/snackbar/error_util.dart' as _i9;
import 'package:flutter_template/viewmodel/global/global_viewmodel.dart' as _i3;
import 'package:icapps_architecture/icapps_architecture.dart' as _i8;
import 'package:mockito/mockito.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i6;

// ignore_for_file: type=lint
Expand All @@ -30,9 +30,19 @@ import 'package:mockito/src/dummies.dart' as _i6;
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class

class _FakeGlobalKey_0<T extends _i1.State<_i1.StatefulWidget>>
extends _i2.SmartFake implements _i1.GlobalKey<T> {
_FakeGlobalKey_0(
class _FakeBuildContext_0 extends _i1.SmartFake implements _i2.BuildContext {
_FakeBuildContext_0(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}

class _FakeGlobalKey_1<T extends _i2.State<_i2.StatefulWidget>>
extends _i1.SmartFake implements _i2.GlobalKey<T> {
_FakeGlobalKey_1(
Object parent,
Invocation parentInvocation,
) : super(
Expand All @@ -44,9 +54,9 @@ class _FakeGlobalKey_0<T extends _i1.State<_i1.StatefulWidget>>
/// A class which mocks [GlobalViewModel].
///
/// See the documentation for Mockito's code generation for more information.
class MockGlobalViewModel extends _i2.Mock implements _i3.GlobalViewModel {
class MockGlobalViewModel extends _i1.Mock implements _i3.GlobalViewModel {
MockGlobalViewModel() {
_i2.throwOnMissingStub(this);
_i1.throwOnMissingStub(this);
}

@override
Expand All @@ -56,10 +66,10 @@ class MockGlobalViewModel extends _i2.Mock implements _i3.GlobalViewModel {
) as List<_i4.Locale>);

@override
_i1.ThemeMode get themeMode => (super.noSuchMethod(
_i2.ThemeMode get themeMode => (super.noSuchMethod(
Invocation.getter(#themeMode),
returnValue: _i1.ThemeMode.system,
) as _i1.ThemeMode);
returnValue: _i2.ThemeMode.system,
) as _i2.ThemeMode);

@override
bool get showsTranslationKeys => (super.noSuchMethod(
Expand Down Expand Up @@ -90,7 +100,7 @@ class MockGlobalViewModel extends _i2.Mock implements _i3.GlobalViewModel {
) as _i5.Future<void>);

@override
_i5.Future<void> updateThemeMode(_i1.ThemeMode? themeMode) =>
_i5.Future<void> updateThemeMode(_i2.ThemeMode? themeMode) =>
(super.noSuchMethod(
Invocation.method(
#updateThemeMode,
Expand Down Expand Up @@ -292,15 +302,15 @@ class MockGlobalViewModel extends _i2.Mock implements _i3.GlobalViewModel {
/// A class which mocks [ErrorUtil].
///
/// See the documentation for Mockito's code generation for more information.
class MockErrorUtil extends _i2.Mock implements _i9.ErrorUtil {
class MockErrorUtil extends _i1.Mock implements _i9.ErrorUtil {
MockErrorUtil() {
_i2.throwOnMissingStub(this);
_i1.throwOnMissingStub(this);
}

@override
String? showError({
required dynamic error,
required _i1.BuildContext? context,
required _i2.BuildContext? context,
}) =>
(super.noSuchMethod(Invocation.method(
#showError,
Expand All @@ -314,7 +324,7 @@ class MockErrorUtil extends _i2.Mock implements _i9.ErrorUtil {
@override
void showErrorWithLocaleKey({
required String? messageKey,
required _i1.BuildContext? context,
required _i2.BuildContext? context,
String? titleKey,
List<dynamic>? args,
}) =>
Expand All @@ -336,19 +346,28 @@ class MockErrorUtil extends _i2.Mock implements _i9.ErrorUtil {
/// A class which mocks [MainNavigator].
///
/// See the documentation for Mockito's code generation for more information.
class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
class MockMainNavigator extends _i1.Mock implements _i10.MainNavigator {
MockMainNavigator() {
_i2.throwOnMissingStub(this);
_i1.throwOnMissingStub(this);
}

@override
_i1.GlobalKey<_i1.NavigatorState> get navigatorKey => (super.noSuchMethod(
_i2.BuildContext get context => (super.noSuchMethod(
Invocation.getter(#context),
returnValue: _FakeBuildContext_0(
this,
Invocation.getter(#context),
),
) as _i2.BuildContext);

@override
_i2.GlobalKey<_i2.NavigatorState> get navigatorKey => (super.noSuchMethod(
Invocation.getter(#navigatorKey),
returnValue: _FakeGlobalKey_0<_i1.NavigatorState>(
returnValue: _FakeGlobalKey_1<_i2.NavigatorState>(
this,
Invocation.getter(#navigatorKey),
),
) as _i1.GlobalKey<_i1.NavigatorState>);
) as _i2.GlobalKey<_i2.NavigatorState>);

@override
_i5.Future<void> goToDatabase(_i11.GeneratedDatabase? db) =>
Expand Down Expand Up @@ -410,14 +429,14 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<void>);

@override
_i1.Route<dynamic>? onGenerateRoute(_i1.RouteSettings? settings) =>
_i2.Route<dynamic>? onGenerateRoute(_i2.RouteSettings? settings) =>
(super.noSuchMethod(Invocation.method(
#onGenerateRoute,
[settings],
)) as _i1.Route<dynamic>?);
)) as _i2.Route<dynamic>?);

@override
void goToHomeScreen({_i1.Key? key}) => super.noSuchMethod(
void goToHomeScreen({_i2.Key? key}) => super.noSuchMethod(
Invocation.method(
#goToHomeScreen,
[],
Expand All @@ -427,7 +446,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
);

@override
void goToSplashScreen({_i1.Key? key}) => super.noSuchMethod(
void goToSplashScreen({_i2.Key? key}) => super.noSuchMethod(
Invocation.method(
#goToSplashScreen,
[],
Expand All @@ -437,7 +456,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
);

@override
_i5.Future<void> goToLicenseScreen({_i1.Key? key}) => (super.noSuchMethod(
_i5.Future<void> goToLicenseScreen({_i2.Key? key}) => (super.noSuchMethod(
Invocation.method(
#goToLicenseScreen,
[],
Expand All @@ -448,7 +467,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<void>);

@override
_i5.Future<void> goToTodoAddScreen({_i1.Key? key}) => (super.noSuchMethod(
_i5.Future<void> goToTodoAddScreen({_i2.Key? key}) => (super.noSuchMethod(
Invocation.method(
#goToTodoAddScreen,
[],
Expand All @@ -459,7 +478,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<void>);

@override
_i5.Future<void> goToAnalyticsPermissionScreen({_i1.Key? key}) =>
_i5.Future<void> goToAnalyticsPermissionScreen({_i2.Key? key}) =>
(super.noSuchMethod(
Invocation.method(
#goToAnalyticsPermissionScreen,
Expand All @@ -471,7 +490,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<void>);

@override
void goToLoginScreen({_i1.Key? key}) => super.noSuchMethod(
void goToLoginScreen({_i2.Key? key}) => super.noSuchMethod(
Invocation.method(
#goToLoginScreen,
[],
Expand All @@ -481,7 +500,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
);

@override
_i5.Future<void> goToThemeModeSelectorScreen({_i1.Key? key}) =>
_i5.Future<void> goToThemeModeSelectorScreen({_i2.Key? key}) =>
(super.noSuchMethod(
Invocation.method(
#goToThemeModeSelectorScreen,
Expand All @@ -493,7 +512,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<void>);

@override
_i5.Future<void> goToDebugPlatformSelectorScreen({_i1.Key? key}) =>
_i5.Future<void> goToDebugPlatformSelectorScreen({_i2.Key? key}) =>
(super.noSuchMethod(
Invocation.method(
#goToDebugPlatformSelectorScreen,
Expand All @@ -505,7 +524,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<void>);

@override
_i5.Future<void> goToDebugScreen({_i1.Key? key}) => (super.noSuchMethod(
_i5.Future<void> goToDebugScreen({_i2.Key? key}) => (super.noSuchMethod(
Invocation.method(
#goToDebugScreen,
[],
Expand All @@ -516,7 +535,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<void>);

@override
_i5.Future<void> goToLogsScreen({_i1.Key? key}) => (super.noSuchMethod(
_i5.Future<void> goToLogsScreen({_i2.Key? key}) => (super.noSuchMethod(
Invocation.method(
#goToLogsScreen,
[],
Expand All @@ -529,7 +548,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
@override
_i5.Future<void> goToLogDetailScreen({
required String? date,
_i1.Key? key,
_i2.Key? key,
}) =>
(super.noSuchMethod(
Invocation.method(
Expand Down Expand Up @@ -564,7 +583,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
);

@override
void popUntil(bool Function(_i1.Route<dynamic>)? predicate) =>
void popUntil(bool Function(_i2.Route<dynamic>)? predicate) =>
super.noSuchMethod(
Invocation.method(
#popUntil,
Expand All @@ -583,7 +602,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
);

@override
_i5.Future<T?> showCustomDialog<T>({_i1.Widget? widget}) =>
_i5.Future<T?> showCustomDialog<T>({_i2.Widget? widget}) =>
(super.noSuchMethod(
Invocation.method(
#showCustomDialog,
Expand All @@ -594,7 +613,7 @@ class MockMainNavigator extends _i2.Mock implements _i10.MainNavigator {
) as _i5.Future<T?>);

@override
_i5.Future<T?> showBottomSheet<T>({_i1.Widget? widget}) =>
_i5.Future<T?> showBottomSheet<T>({_i2.Widget? widget}) =>
(super.noSuchMethod(
Invocation.method(
#showBottomSheet,
Expand Down
Loading

0 comments on commit 02686c9

Please sign in to comment.