Skip to content

Commit 2ec1283

Browse files
Stitch-TaotaoBungeefan
authored andcommitted
add custom excludePaths properties in pretty_printer
1 parent d672c9c commit 2ec1283

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

lib/src/printers/pretty_printer.dart

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class PrettyPrinter extends LogPrinter {
8484
/// (boxing can still be turned on for some levels by using something like excludeBox:{Level.error:false} )
8585
final bool noBoxingByDefault;
8686

87+
/// To exclude user's custom path
88+
/// for example if you made a Mylog util redirect to logger.log,
89+
/// you can add your Mylog path in [excludePaths].
90+
final List<String> excludePaths;
8791
late final Map<Level, bool> includeBox;
8892

8993
String _topBorder = '';
@@ -100,6 +104,7 @@ class PrettyPrinter extends LogPrinter {
100104
this.printTime = false,
101105
this.excludeBox = const {},
102106
this.noBoxingByDefault = false,
107+
this.excludePaths = const [],
103108
}) {
104109
_startTime ??= DateTime.now();
105110

@@ -180,30 +185,50 @@ class PrettyPrinter extends LogPrinter {
180185
}
181186
}
182187

188+
bool _isInExcludePaths(String segment) {
189+
for (var element in excludePaths) {
190+
if (segment.startsWith(element)) {
191+
return true;
192+
}
193+
}
194+
return false;
195+
}
196+
183197
bool _discardDeviceStacktraceLine(String line) {
184198
var match = _deviceStackTraceRegex.matchAsPrefix(line);
185199
if (match == null) {
186200
return false;
187201
}
188-
return match.group(2)!.startsWith('package:logger');
202+
final segment = match.group(2)!;
203+
if (segment.startsWith('package:logger')) {
204+
return true;
205+
}
206+
return _isInExcludePaths(segment);
189207
}
190208

191209
bool _discardWebStacktraceLine(String line) {
192210
var match = _webStackTraceRegex.matchAsPrefix(line);
193211
if (match == null) {
194212
return false;
195213
}
196-
return match.group(1)!.startsWith('packages/logger') ||
197-
match.group(1)!.startsWith('dart-sdk/lib');
214+
final segment = match.group(1)!;
215+
if (segment.startsWith('packages/logger') ||
216+
segment.startsWith('dart-sdk/lib')) {
217+
return true;
218+
}
219+
return _isInExcludePaths(segment);
198220
}
199221

200222
bool _discardBrowserStacktraceLine(String line) {
201223
var match = _browserStackTraceRegex.matchAsPrefix(line);
202224
if (match == null) {
203225
return false;
204226
}
205-
return match.group(1)!.startsWith('package:logger') ||
206-
match.group(1)!.startsWith('dart:');
227+
final segment = match.group(1)!;
228+
if (segment.startsWith('package:logger') || segment.startsWith('dart:')) {
229+
return true;
230+
}
231+
return _isInExcludePaths(segment);
207232
}
208233

209234
String getTime(DateTime time) {

0 commit comments

Comments
 (0)