Skip to content

Commit ed3e07a

Browse files
we-kislay-k001we-prajapati-c001
authored andcommitted
fixed: error, stacktrace, data, hint, & message
1 parent 9969374 commit ed3e07a

File tree

9 files changed

+137
-100
lines changed

9 files changed

+137
-100
lines changed

lib/vaahextendflutter/env/env.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class EnvController extends GetxController {
3232
throw Exception('Environment configuration not found for key: $envPath');
3333
}
3434
} catch (error, stackTrace) {
35-
Log.exception(error, stackTrace: stackTrace);
35+
Log.exception(
36+
"error-occured-while-initializing-env-controller",
37+
throwable: error,
38+
stackTrace: stackTrace,
39+
);
3640
exit(0);
3741
}
3842
}

lib/vaahextendflutter/services/api.dart

+11-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ abstract class Api {
348348
bool showAlert,
349349
String alertType,
350350
) async {
351-
Log.exception(error, stackTrace: error.stackTrace);
351+
Log.exception(
352+
"handle-timeout-error",
353+
throwable: error,
354+
stackTrace: error.stackTrace,
355+
);
352356
if (showAlert) {
353357
if (alertType == 'dialog') {
354358
if (Alerts.showErrorDialog != null) {
@@ -416,7 +420,12 @@ abstract class Api {
416420

417421
if (error.response?.data != null) {
418422
try {
419-
Log.exception(catchErr, data: error.response, stackTrace: stackTrace);
423+
Log.exception(
424+
"handle-response-error",
425+
throwable: catchErr,
426+
stackTrace: stackTrace,
427+
hint: error.response,
428+
);
420429

421430
final Map<String, dynamic> response = error.response?.data as Map<String, dynamic>;
422431
if (response['errors'] != null) {

lib/vaahextendflutter/services/logging_library/_cloud/firebase_logging_service.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import '../models/log.dart';
22
import 'logging_service.dart';
33

44
abstract class FirebaseLoggingService implements LoggingService {
5-
static logEvent({
6-
required String message,
7-
EventType? type,
5+
static logEvent(
6+
String message, {
87
Object? data,
8+
EventType? type,
99
}) =>
1010
throw UnimplementedError();
1111

1212
static logException(
13-
dynamic throwable, {
14-
dynamic stackTrace,
13+
String message, {
14+
Object? throwable,
15+
StackTrace? stackTrace,
1516
dynamic hint,
1617
}) =>
1718
throw UnimplementedError();

lib/vaahextendflutter/services/logging_library/_cloud/sentry_logging_service.dart

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import '../models/log.dart';
44
import 'logging_service.dart';
55

66
abstract class SentryLoggingService implements LoggingService {
7-
static logEvent({
8-
required String message,
9-
SentryLevel? level,
7+
static logEvent(
8+
String message, {
109
Object? data,
10+
SentryLevel? level,
1111
}) {
1212
final SentryEvent event = SentryEvent(message: SentryMessage(message), level: level);
1313
Sentry.captureEvent(
@@ -17,11 +17,19 @@ abstract class SentryLoggingService implements LoggingService {
1717
}
1818

1919
static logException(
20-
dynamic throwable, {
21-
dynamic stackTrace,
20+
String message, {
21+
Object? throwable,
22+
StackTrace? stackTrace,
2223
dynamic hint,
2324
}) {
24-
Sentry.captureException(throwable, stackTrace: stackTrace, hint: hint);
25+
Sentry.captureException(
26+
throwable,
27+
stackTrace: stackTrace,
28+
hint: Hint.withMap({
29+
"message": message,
30+
"hint": hint,
31+
}),
32+
);
2533
}
2634

2735
static logTransaction({

lib/vaahextendflutter/services/logging_library/_local/console_service.dart

+52-45
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import 'package:flutter/material.dart';
66
import '../models/log.dart';
77

88
class Console {
9-
static void _printChunks(Colorize text) {
9+
static void _printLog(
10+
String text, {
11+
Styles? style,
12+
}) {
1013
final RegExp pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
11-
pattern.allMatches(text.toString()).forEach(
12-
(RegExpMatch match) => debugPrint(
13-
match.group(0),
14-
),
15-
);
16-
}
17-
18-
static void _printLog(Colorize text) {
19-
_printChunks(text);
14+
pattern.allMatches(text).forEach((RegExpMatch match) {
15+
if (style == null) {
16+
return debugPrint(match.group(0));
17+
}
18+
Colorize chunk = Colorize(match.group(0).toString()).apply(style);
19+
return debugPrint('$chunk');
20+
});
2021
}
2122

2223
static String _parseData(Object? data) {
@@ -29,62 +30,68 @@ class Console {
2930
}
3031
}
3132

32-
static void log(String text, [Object? data]) {
33-
Colorize txt = Colorize(text);
34-
_printLog(txt);
33+
static void log(
34+
String message, {
35+
Object? data,
36+
}) {
37+
_printLog(message);
3538

3639
if (data != null) {
37-
Colorize dataColor = Colorize(_parseData(data));
38-
dataColor.white();
39-
_printLog(dataColor);
40+
_printLog(_parseData(data));
4041
}
4142
}
4243

43-
static void info(String text, [Object? data]) {
44-
Colorize txt = Colorize(text);
45-
txt.blue();
46-
_printLog(txt);
44+
static void info(
45+
String message, {
46+
Object? data,
47+
}) {
48+
_printLog(message, style: Styles.BLUE);
4749

4850
if (data != null) {
49-
Colorize dataColor = Colorize(_parseData(data));
50-
dataColor.blue();
51-
_printLog(dataColor);
51+
_printLog(_parseData(data), style: Styles.BLUE);
5252
}
5353
}
5454

55-
static void success(String text, [Object? data]) {
56-
Colorize txt = Colorize(text);
57-
txt.green();
58-
_printLog(txt);
55+
static void success(
56+
String message, {
57+
Object? data,
58+
}) {
59+
_printLog(message, style: Styles.GREEN);
5960

6061
if (data != null) {
61-
Colorize dataColor = Colorize(_parseData(data));
62-
dataColor.green();
63-
_printLog(dataColor);
62+
_printLog(_parseData(data), style: Styles.GREEN);
6463
}
6564
}
6665

67-
static void warning(String text, [Object? data]) {
68-
Colorize txt = Colorize(text);
69-
txt.yellow();
70-
_printLog(txt);
66+
static void warning(
67+
String message, {
68+
Object? data,
69+
}) {
70+
_printLog(message, style: Styles.YELLOW);
7171

7272
if (data != null) {
73-
Colorize dataColor = Colorize(_parseData(data));
74-
dataColor.yellow();
75-
_printLog(dataColor);
73+
_printLog(_parseData(data), style: Styles.YELLOW);
7674
}
7775
}
7876

79-
static void danger(String text, [Object? data]) {
80-
Colorize txt = Colorize(text);
81-
txt.red();
82-
_printLog(txt);
77+
static void danger(
78+
String message, {
79+
Object? throwable,
80+
StackTrace? stackTrace,
81+
dynamic hint,
82+
}) {
83+
_printLog(message, style: Styles.RED);
8384

84-
if (data != null) {
85-
Colorize dataColor = Colorize(_parseData(data));
86-
dataColor.red();
87-
_printLog(dataColor);
85+
if (throwable != null) {
86+
_printLog(_parseData(throwable), style: Styles.RED);
87+
}
88+
89+
if (stackTrace != null) {
90+
_printLog(stackTrace.toString(), style: Styles.RED);
91+
}
92+
93+
if (hint != null) {
94+
_printLog(_parseData(hint), style: Styles.RED);
8895
}
8996
}
9097

lib/vaahextendflutter/services/logging_library/logging_library.dart

+32-29
Original file line numberDiff line numberDiff line change
@@ -13,91 +13,94 @@ class Log {
1313
];
1414

1515
static void log(
16-
dynamic text, {
16+
String message, {
1717
Object? data,
1818
bool disableLocalLogging = false,
1919
bool disableCloudLogging = false,
2020
}) {
2121
if (_config.enableLocalLogs && !disableLocalLogging) {
22-
Console.log(text.toString(), data);
22+
Console.log(message, data: data);
2323
}
2424
if (_config.enableCloudLogs && !disableCloudLogging) {
25-
_logEvent(text.toString(), data: data, type: EventType.log);
25+
_logEvent(message, data: data, type: EventType.log);
2626
}
2727
}
2828

2929
static void info(
30-
dynamic text, {
30+
String message, {
3131
Object? data,
3232
bool disableLocalLogging = false,
3333
bool disableCloudLogging = false,
3434
}) {
3535
if (_config.enableLocalLogs && !disableLocalLogging) {
36-
Console.info(text.toString(), data);
36+
Console.info(message, data: data);
3737
}
3838
if (_config.enableCloudLogs && !disableCloudLogging) {
39-
_logEvent(text.toString(), data: data, type: EventType.info);
39+
_logEvent(message, data: data, type: EventType.info);
4040
}
4141
}
4242

4343
static void success(
44-
dynamic text, {
44+
String message, {
4545
Object? data,
4646
bool disableLocalLogging = false,
4747
bool disableCloudLogging = false,
4848
}) {
4949
if (_config.enableLocalLogs && !disableLocalLogging) {
50-
Console.success(text.toString(), data);
50+
Console.success(message, data: data);
5151
}
5252
if (_config.enableCloudLogs && !disableCloudLogging) {
53-
_logEvent(text.toString(), data: data, type: EventType.success);
53+
_logEvent(message, data: data, type: EventType.success);
5454
}
5555
}
5656

5757
static void warning(
58-
dynamic text, {
58+
String message, {
5959
Object? data,
6060
bool disableLocalLogging = false,
6161
bool disableCloudLogging = false,
6262
}) {
6363
if (_config.enableLocalLogs && !disableLocalLogging) {
64-
Console.warning(text.toString(), data);
64+
Console.warning(message, data: data);
6565
}
6666
if (_config.enableCloudLogs && !disableCloudLogging) {
67-
_logEvent(text.toString(), data: data, type: EventType.warning);
67+
_logEvent(message, data: data, type: EventType.warning);
6868
}
6969
}
7070

7171
static void exception(
72-
dynamic throwable, {
73-
Object? data,
74-
dynamic stackTrace,
72+
String message, {
73+
Object? throwable,
74+
StackTrace? stackTrace,
7575
dynamic hint,
7676
bool disableLocalLogging = false,
7777
bool disableCloudLogging = false,
7878
}) {
7979
if (_config.enableLocalLogs && !disableLocalLogging) {
80-
Console.danger('$throwable\n$hint', data);
80+
Console.danger(
81+
message,
82+
throwable: throwable,
83+
stackTrace: stackTrace,
84+
hint: hint,
85+
);
8186
}
8287
if (_config.enableCloudLogs && !disableCloudLogging) {
83-
final hintWithData = {
84-
'hint': hint,
85-
'data': data,
86-
};
8788
for (final service in _services) {
8889
switch (service) {
8990
case const (SentryLoggingService):
9091
SentryLoggingService.logException(
91-
throwable,
92+
message,
93+
throwable: throwable,
9294
stackTrace: stackTrace,
93-
hint: hintWithData,
95+
hint: hint,
9496
);
9597
return;
9698
case const (FirebaseLoggingService):
9799
FirebaseLoggingService.logException(
98-
throwable,
100+
message,
101+
throwable: throwable,
99102
stackTrace: stackTrace,
100-
hint: hintWithData,
103+
hint: hint,
101104
);
102105
return;
103106
default:
@@ -139,24 +142,24 @@ class Log {
139142
}
140143

141144
static void _logEvent(
142-
String text, {
145+
String message, {
143146
Object? data,
144147
EventType? type,
145148
}) {
146149
for (final service in _services) {
147150
switch (service) {
148151
case const (SentryLoggingService):
149152
SentryLoggingService.logEvent(
150-
message: text,
151-
level: type?.toSentryLevel,
153+
message,
152154
data: data,
155+
level: type?.toSentryLevel,
153156
);
154157
return;
155158
case const (FirebaseLoggingService):
156159
FirebaseLoggingService.logEvent(
157-
message: text,
158-
type: type,
160+
message,
159161
data: data,
162+
type: type,
160163
);
161164
return;
162165
default:

0 commit comments

Comments
 (0)