Skip to content

Commit

Permalink
chore: added logman
Browse files Browse the repository at this point in the history
  • Loading branch information
JideGuru committed Dec 25, 2023
1 parent e704cff commit 3d593eb
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 31 deletions.
6 changes: 3 additions & 3 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_fimber: 4a6b342666fecb329fca23143f4b72c46cdd8022
flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721
fluttertoast: eb263d302cc92e04176c053d2385237e9f43fad0
flutter_inappwebview: 3d32228f1304635e7c028b0d4252937730bbc6cf
fluttertoast: 48c57db1b71b0ce9e6bba9f31c940ff4b001293c
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
Expand All @@ -90,4 +90,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 775997f741c536251164e3eacf6e34abf2eb7a17

COCOAPODS: 1.11.3
COCOAPODS: 1.14.2
7 changes: 6 additions & 1 deletion lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_ebook_app/src/common/common.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:logman/logman.dart';

class MyApp extends ConsumerWidget {
MyApp({super.key});
Expand All @@ -21,7 +22,11 @@ class MyApp extends ConsumerWidget {
),
darkTheme: themeData(ThemeConfig.darkTheme),
themeMode: currentAppTheme.value?.themeMode,
routerConfig: _appRouter.config(),
routerConfig: _appRouter.config(
navigatorObservers: () => [
LogmanNavigatorObserver(),
],
),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter_ebook_app/src/common/common.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logman/logman.dart';
import 'package:sembast/sembast.dart';

class DownloadsLocalDataSourceImpl implements DownloadsLocalDataSource {
Expand All @@ -15,21 +16,33 @@ class DownloadsLocalDataSourceImpl implements DownloadsLocalDataSource {
@override
Future<void> addBook(Map<String, dynamic> book, String id) async {
await _store.record(id).put(_database, book, merge: true);
Logman.instance.recordSimpleLog(
'Added book to downloads: ${book['title']}',
);
}

@override
Future<void> clearBooks() async {
await _store.delete(_database);
Logman.instance.recordSimpleLog(
'Cleared all books from downloads',
);
}

@override
Future<void> deleteAllBooksWithId(String id) async {
await _store.record(id).delete(_database);
Logman.instance.recordSimpleLog(
'Deleted all books with id: $id',
);
}

@override
Future<void> deleteBook(String id) async {
await _store.record(id).delete(_database);
Logman.instance.recordSimpleLog(
'Deleted book from downloads: $id',
);
}

@override
Expand All @@ -41,6 +54,9 @@ class DownloadsLocalDataSourceImpl implements DownloadsLocalDataSource {

@override
Future<Map<String, dynamic>?> fetchBook(String id) async {
Logman.instance.recordSimpleLog(
'Fetched book from downloads: $id',
);
return _store.record(id).get(_database);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter_ebook_app/src/common/common.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logman/logman.dart';
import 'package:sembast/sembast.dart';

class FavoritesLocalDataSourceImpl implements FavoritesLocalDataSource {
Expand All @@ -15,11 +16,17 @@ class FavoritesLocalDataSourceImpl implements FavoritesLocalDataSource {
@override
Future<void> addBook(Entry book, String id) async {
await _store.record(id).put(_database, book.toJson());
Logman.instance.recordSimpleLog(
'Added book to favorites: ${book.title}',
);
}

@override
Future<void> deleteBook(String id) async {
await _store.record(id).delete(_database);
Logman.instance.recordSimpleLog(
'Deleted book from favorites: $id',
);
}

@override
Expand Down
100 changes: 86 additions & 14 deletions lib/src/common/data/remote/app_dio.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ebook_app/src/common/common.dart';
import 'package:logman/logman.dart';

class AppDio with DioMixin implements Dio {
AppDio._() {
Expand All @@ -12,22 +14,92 @@ class AppDio with DioMixin implements Dio {
sendTimeout: const Duration(milliseconds: 30000),
receiveTimeout: const Duration(milliseconds: 30000),
);
interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) async {
options.headers['Content-Type'] = 'application/json';
return handler.next(options);
},
onResponse: (response, handler) {
return handler.next(response);
},
onError: (DioError e, handler) async {
return handler.next(e);
},
),
);
interceptors
..add(
InterceptorsWrapper(
onRequest: (options, handler) async {
options.headers['Content-Type'] = 'application/json';
return handler.next(options);
},
onResponse: (response, handler) {
return handler.next(response);
},
onError: (DioException e, handler) async {
return handler.next(e);
},
),
)
..add(LogmanDioInterceptor());
httpClientAdapter = IOHttpClientAdapter();
}

static Dio getInstance() => AppDio._();
}

class LogmanDioInterceptor extends Interceptor {
final Logman _logman = Logman.instance;

LogmanDioInterceptor();

final _cache = <RequestOptions, String>{};

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final requestId = UniqueKey().toString();
_cache[options] = requestId;
final sentAt = DateTime.now();

final requestRecord = NetworkRequestLogmanRecord(
id: requestId,
url: options.uri.toString(),
method: options.method,
headers: options.headers,
body: options.data,
sentAt: sentAt,
);
_logman.recordNetworkRequest(requestRecord);

return super.onRequest(options, handler);
}

@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
final Map<String, String> responseHeaders = response.headers.map.map(
(key, value) => MapEntry(key, value.join(', ')),
);
final id = _cache[response.requestOptions];
final receivedAt = DateTime.now();

final responseRecord = NetworkResponseLogmanRecord(
id: id!,
statusCode: response.statusCode,
headers: responseHeaders,
body: response.data.toString(),
receivedAt: receivedAt,
);

_logman.recordNetworkResponse(responseRecord);

return super.onResponse(response, handler);
}

@override
void onError(DioException err, ErrorInterceptorHandler handler) {
final Map<String, String>? responseHeaders = err.response?.headers.map.map(
(key, value) => MapEntry(key, value.join(', ')),
);
final id = _cache[err.requestOptions];

final responseRecord = NetworkResponseLogmanRecord(
id: id!,
statusCode: err.response?.statusCode ?? 0,
headers: responseHeaders,
body: err.response?.data.toString(),
receivedAt: DateTime.now(),
);

_logman.recordNetworkResponse(responseRecord);

return super.onError(err, handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DownloadAlert extends ConsumerStatefulWidget {
}

class _DownloadAlertState extends ConsumerState<DownloadAlert> {
Dio dio = Dio();
Dio dio = Dio()..interceptors.add(LogmanDioInterceptor());
int received = 0;
String progress = '0';
int total = 0;
Expand Down
15 changes: 15 additions & 0 deletions lib/src/features/splash/presentation/ui/screens/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ebook_app/src/common/common.dart';
import 'package:logman/logman.dart';

@RoutePage()
class SplashScreen extends StatefulWidget {
Expand All @@ -29,6 +30,20 @@ class _SplashScreenState extends State<SplashScreen> {
void initState() {
super.initState();
startTimeout();
WidgetsBinding.instance.addPostFrameCallback((_) {
Logman.instance.attachOverlay(
context: context,
button: FloatingActionButton(
elevation: 0,
onPressed: () {},
backgroundColor: context.theme.accentColor,
child: const Icon(
Icons.bug_report,
color: Colors.white,
),
),
);
});
}

@override
Expand Down
2 changes: 1 addition & 1 deletion macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

COCOAPODS: 1.11.3
COCOAPODS: 1.14.2
2 changes: 1 addition & 1 deletion macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
28 changes: 22 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ packages:
dependency: "direct main"
description:
name: dio
sha256: "347d56c26d63519552ef9a569f2a593dda99a81fdbdff13c584b7197cfe05059"
sha256: "797e1e341c3dd2f69f2dad42564a6feff3bfb87187d05abb93b9609e6f1645c3"
url: "https://pub.dev"
source: hosted
version: "5.1.2"
version: "5.4.0"
equatable:
dependency: transitive
description:
Expand Down Expand Up @@ -400,13 +400,13 @@ packages:
source: git
version: "2.0.0"
flutter_inappwebview:
dependency: transitive
dependency: "direct overridden"
description:
name: flutter_inappwebview
sha256: f73505c792cf083d5566e1a94002311be497d984b5607f25be36d685cf6361cf
sha256: d198297060d116b94048301ee6749cd2e7d03c1f2689783f52d210a6b7aba350
url: "https://pub.dev"
source: hosted
version: "5.7.2+3"
version: "5.8.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -601,6 +601,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.1"
logger:
dependency: transitive
description:
name: logger
sha256: "6bbb9d6f7056729537a4309bda2e74e18e5d9f14302489cc1e93f33b3fe32cac"
url: "https://pub.dev"
source: hosted
version: "2.0.2+1"
logging:
dependency: transitive
description:
Expand All @@ -609,6 +617,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
logman:
dependency: "direct main"
description:
name: logman
sha256: "32d426a00336dff1d01a5cc5e5315563e58fba1bcafc531a122e923fb0f117a0"
url: "https://pub.dev"
source: hosted
version: "0.0.5"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1360,5 +1376,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
dart: ">=3.1.0 <4.0.0"
flutter: ">=3.7.0"
8 changes: 5 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
auto_route: ^7.4.0
cached_network_image: ^3.2.3
cupertino_icons: ^1.0.3
dio: ^5.1.2
dio: ^5.4.0
flutter:
sdk: flutter
flutter_icons:
Expand All @@ -19,6 +19,9 @@ dependencies:
flutter_spinkit: ^5.2.0
freezed_annotation: ^2.2.0
google_fonts: ^4.0.4
iridium_reader_widget:
path: ./packages/iridium/reader_widget
logman: ^0.0.5
path: ^1.8.2
path_provider: ^2.0.3
permission_handler: ^10.2.0
Expand All @@ -28,11 +31,10 @@ dependencies:
share_plus: ^4.0.4
shared_preferences: ^2.1.1
xml2json: ^5.3.1
iridium_reader_widget:
path: ./packages/iridium/reader_widget

dependency_overrides:
collection: ^1.17.2
flutter_inappwebview: ^5.8.0

dev_dependencies:
auto_route_generator: ^7.1.1
Expand Down

0 comments on commit 3d593eb

Please sign in to comment.