Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature -> Develop | Task 9427 Colored Stacktrace #38

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/vaahextendflutter/env/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class EnvController extends GetxController {
throw Exception('Environment configuration not found for key: $envPath');
}
} catch (error, stackTrace) {
Log.exception(error, stackTrace: stackTrace);
Log.exception(
"Error occured while initializing EnvController",
throwable: error,
stackTrace: stackTrace,
);
exit(0);
}
}
Expand Down
13 changes: 11 additions & 2 deletions lib/vaahextendflutter/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ abstract class Api {
bool showAlert,
String alertType,
) async {
Log.exception(error, stackTrace: error.stackTrace);
Log.exception(
"Handle Timeout Error",
throwable: error,
stackTrace: error.stackTrace,
);
if (showAlert) {
if (alertType == 'dialog') {
if (Alerts.showErrorDialog != null) {
Expand Down Expand Up @@ -416,7 +420,12 @@ abstract class Api {

if (error.response?.data != null) {
try {
Log.exception(catchErr, data: error.response, stackTrace: stackTrace);
Log.exception(
"Handle Response Error",
throwable: catchErr,
hint: error.response,
stackTrace: stackTrace,
);

final Map<String, dynamic> response = error.response?.data as Map<String, dynamic>;
if (response['errors'] != null) {
Expand Down
21 changes: 12 additions & 9 deletions lib/vaahextendflutter/services/dynamic_links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class DynamicLinks {
shortLinkType: ShortDynamicLinkType.unguessable,
);
} catch (error, stackTrace) {
Log.exception(error, stackTrace: stackTrace, hint: "Error creating dynamic link!");
Log.exception("Error creating dynamic link!", throwable: error, stackTrace: stackTrace);
return null;
}
}
Expand All @@ -61,10 +61,13 @@ abstract class DynamicLinks {
decoded: "${linkData.link.host}${linkData.link.path}?payload=$payload",
),
);
Log.success({
"encoded": linkData.link.toString(),
"decoded": "${linkData.link.host}${linkData.link.path}?payload=$payload",
});
Log.success(
"Handle Deeplink",
data: {
"encoded": linkData.link.toString(),
"decoded": "${linkData.link.host}${linkData.link.path}?payload=$payload",
},
);
if (payload != null && payload['path'] != null) {
Get.to(
payload['path'],
Expand All @@ -76,9 +79,9 @@ abstract class DynamicLinks {
}
} catch (error, stackTrace) {
Log.exception(
error,
"Error handling dynamic link! ${linkData.asMap()}",
throwable: error,
stackTrace: stackTrace,
hint: "Error handling dynamic link! ${linkData.asMap()}",
);
}
}
Expand All @@ -88,9 +91,9 @@ abstract class DynamicLinks {
return jsonDecode(link.queryParameters['payload'].toString());
} catch (error, stackTrace) {
Log.exception(
error,
"Error decoding payload! $link",
throwable: error,
stackTrace: stackTrace,
hint: "Error decoding payload! $link",
);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import '../models/log.dart';
import 'logging_service.dart';

abstract class FirebaseLoggingService implements LoggingService {
static logEvent({
required String message,
EventType? type,
static logEvent(
String message, {
Object? data,
EventType? type,
}) =>
throw UnimplementedError();

static logException(
dynamic throwable, {
dynamic stackTrace,
String message, {
Object? throwable,
StackTrace? stackTrace,
dynamic hint,
}) =>
throw UnimplementedError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import '../models/log.dart';
import 'logging_service.dart';

abstract class SentryLoggingService implements LoggingService {
static logEvent({
required String message,
SentryLevel? level,
static logEvent(
String message, {
Object? data,
SentryLevel? level,
}) {
final SentryEvent event = SentryEvent(message: SentryMessage(message), level: level);
Sentry.captureEvent(
Expand All @@ -17,11 +17,19 @@ abstract class SentryLoggingService implements LoggingService {
}

static logException(
dynamic throwable, {
dynamic stackTrace,
String message, {
Object? throwable,
StackTrace? stackTrace,
dynamic hint,
}) {
Sentry.captureException(throwable, stackTrace: stackTrace, hint: hint);
Sentry.captureException(
throwable,
stackTrace: stackTrace,
hint: Hint.withMap({
"message": message,
"hint": hint,
}),
);
}

static logTransaction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import 'package:flutter/material.dart';
import '../models/log.dart';

class Console {
static void _printChunks(Colorize text) {
we-prajapati-c001 marked this conversation as resolved.
Show resolved Hide resolved
static void _printLog(String text, [Set<Styles>? logStyle]) {
final RegExp pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(text.toString()).forEach(
(RegExpMatch match) => debugPrint(
match.group(0),
),
);
}

static void _printLog(Colorize text) {
_printChunks(text);
pattern.allMatches(text).forEach((RegExpMatch match) {
if (logStyle == null || logStyle.isEmpty) {
return debugPrint(match.group(0));
}
Colorize chunk = Colorize(match.group(0).toString()).apply(logStyle.first);
return debugPrint('$chunk');
});
}

static String _parseData(Object? data) {
Expand All @@ -29,62 +27,98 @@ class Console {
}
}

static void log(String text, [Object? data]) {
Colorize txt = Colorize(text);
_printLog(txt);
static void log(
String message, {
Object? data,
}) {
_printLog(message);

if (data != null) {
Colorize dataColor = Colorize(_parseData(data));
dataColor.white();
_printLog(dataColor);
_printLog(_parseData(data));
}
}

static void info(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.blue();
_printLog(txt);
static void info(
String message, {
Object? data,
}) {
_printLog(
message,
{Styles.BLUE},
);

if (data != null) {
Colorize dataColor = Colorize(_parseData(data));
dataColor.blue();
_printLog(dataColor);
_printLog(
_parseData(data),
{Styles.BLUE},
);
}
}

static void success(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.green();
_printLog(txt);
static void success(
String message, {
Object? data,
}) {
_printLog(
message,
{Styles.GREEN},
);

if (data != null) {
Colorize dataColor = Colorize(_parseData(data));
dataColor.green();
_printLog(dataColor);
_printLog(
_parseData(data),
{Styles.GREEN},
);
}
}

static void warning(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.yellow();
_printLog(txt);
static void warning(
String message, {
Object? data,
}) {
_printLog(
message,
{Styles.YELLOW},
);

if (data != null) {
Colorize dataColor = Colorize(_parseData(data));
dataColor.yellow();
_printLog(dataColor);
_printLog(
_parseData(data),
{Styles.YELLOW},
);
}
}

static void danger(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.red();
_printLog(txt);
static void danger(
String message, {
Object? throwable,
StackTrace? stackTrace,
dynamic hint,
}) {
_printLog(
message,
{Styles.RED},
);

if (throwable != null) {
_printLog(
_parseData(throwable),
{Styles.RED},
);
}

if (stackTrace != null) {
_printLog(
stackTrace.toString(),
{Styles.RED},
);
}

if (data != null) {
Colorize dataColor = Colorize(_parseData(data));
dataColor.red();
_printLog(dataColor);
if (hint != null) {
_printLog(
_parseData(hint),
{Styles.RED},
);
}
}

Expand Down
Loading