Skip to content

Commit

Permalink
Updated: colored stack trace on log
Browse files Browse the repository at this point in the history
  • Loading branch information
we-kislay-k001 authored and we-prajapati-c001 committed Oct 22, 2024
1 parent 94c5501 commit 6f50e89
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<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),
),
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) {
Expand All @@ -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,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 6f50e89

Please sign in to comment.