From e42391cd60fb19c8c6826f9b352cd955e9646811 Mon Sep 17 00:00:00 2001 From: Kislay Kumar Date: Sat, 6 Apr 2024 11:56:17 +0530 Subject: [PATCH] Updated: colored stack trace on log --- .../_local/console_service.dart | 76 ++++++++++--------- .../logging_library/logging_library.dart | 2 +- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/vaahextendflutter/services/logging_library/_local/console_service.dart b/lib/vaahextendflutter/services/logging_library/_local/console_service.dart index 748dd83..5bd685a 100644 --- a/lib/vaahextendflutter/services/logging_library/_local/console_service.dart +++ b/lib/vaahextendflutter/services/logging_library/_local/console_service.dart @@ -6,17 +6,20 @@ import 'package:flutter/material.dart'; import '../models/log.dart'; class Console { - static void _printChunks(Colorize text) { + static void _printLog(String text, [Set? 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), - ), + pattern.allMatches(text).forEach((RegExpMatch match) { + if (logStyle == null || logStyle.isEmpty) { + return debugPrint( + match.group(0), ); - } + } - static void _printLog(Colorize text) { - _printChunks(text); + Colorize chunk = Colorize(match.group(0).toString()).apply(logStyle.first); + return debugPrint( + '$chunk', + ); + }); } static String _parseData(Object? data) { @@ -30,61 +33,60 @@ class Console { } static void log(String text, [Object? data]) { - Colorize txt = Colorize(text); - _printLog(txt); + _printLog(text); if (data != null) { - Colorize dataColor = Colorize(_parseData(data)); - dataColor.white(); - _printLog(dataColor); + _printLog(_parseData(data), { + Styles.WHITE, + }); } } static void info(String text, [Object? data]) { - Colorize txt = Colorize(text); - txt.blue(); - _printLog(txt); + _printLog(text, { + 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); + _printLog(text, { + 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); + _printLog(text, { + 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); + _printLog(text, { + Styles.RED, + }); if (data != null) { - Colorize dataColor = Colorize(_parseData(data)); - dataColor.red(); - _printLog(dataColor); + _printLog(_parseData(data), { + Styles.RED, + }); } } diff --git a/lib/vaahextendflutter/services/logging_library/logging_library.dart b/lib/vaahextendflutter/services/logging_library/logging_library.dart index 7f73a51..3f57f68 100644 --- a/lib/vaahextendflutter/services/logging_library/logging_library.dart +++ b/lib/vaahextendflutter/services/logging_library/logging_library.dart @@ -77,7 +77,7 @@ class Log { bool disableCloudLogging = false, }) { if (_config.enableLocalLogs && !disableLocalLogging) { - Console.danger('$throwable\n$hint', data); + Console.danger('$throwable\n$hint\n$stackTrace', data); } if (_config.enableCloudLogs && !disableCloudLogging) { final hintWithData = {