@@ -74,25 +74,33 @@ class PrettyPrinter extends LogPrinter {
74
74
/// * [excludePaths]
75
75
final int stackTraceBeginIndex;
76
76
77
- /// Controls the method count in created stack traces.
77
+ /// Controls the method count in stack traces
78
+ /// when no [LogEvent.error] was provided.
78
79
///
79
- /// This is used when no stack trace has been provided.
80
+ /// In case no [LogEvent.stackTrace] was provided,
81
+ /// [StackTrace.current] will be used to create one.
80
82
///
81
- /// Set to `0` to disable the creation of a stack trace.
83
+ /// * Set to `0` in order to disable printing a stack trace
84
+ /// without an error parameter.
85
+ /// * Set to `null` to remove the method count limit all together.
82
86
///
83
87
/// See also:
84
88
/// * [errorMethodCount]
85
- final int methodCount;
89
+ final int ? methodCount;
86
90
87
- /// Controls the method count in provided stack traces.
91
+ /// Controls the method count in stack traces
92
+ /// when [LogEvent.error] was provided.
88
93
///
89
- /// This is used when a stack trace was provided via the error parameter.
94
+ /// In case no [LogEvent.stackTrace] was provided,
95
+ /// [StackTrace.current] will be used to create one.
90
96
///
91
- /// Set to `0` in order to disable printing the provided stack trace.
97
+ /// * Set to `0` in order to disable printing a stack trace
98
+ /// in case of an error parameter.
99
+ /// * Set to `null` to remove the method count limit all together.
92
100
///
93
101
/// See also:
94
102
/// * [methodCount]
95
- final int errorMethodCount;
103
+ final int ? errorMethodCount;
96
104
97
105
/// Controls the length of the divider lines.
98
106
final int lineLength;
@@ -203,12 +211,18 @@ class PrettyPrinter extends LogPrinter {
203
211
var messageStr = stringifyMessage (event.message);
204
212
205
213
String ? stackTraceStr;
206
- if (event.stackTrace == null ) {
207
- if (methodCount > 0 ) {
208
- stackTraceStr = formatStackTrace (StackTrace .current, methodCount);
214
+ if (event.error != null ) {
215
+ if ((errorMethodCount == null || errorMethodCount! > 0 )) {
216
+ stackTraceStr = formatStackTrace (
217
+ event.stackTrace ?? StackTrace .current,
218
+ errorMethodCount,
219
+ );
209
220
}
210
- } else if (errorMethodCount > 0 ) {
211
- stackTraceStr = formatStackTrace (event.stackTrace, errorMethodCount);
221
+ } else if (methodCount == null || methodCount! > 0 ) {
222
+ stackTraceStr = formatStackTrace (
223
+ event.stackTrace ?? StackTrace .current,
224
+ methodCount,
225
+ );
212
226
}
213
227
214
228
var errorStr = event.error? .toString ();
@@ -227,7 +241,7 @@ class PrettyPrinter extends LogPrinter {
227
241
);
228
242
}
229
243
230
- String ? formatStackTrace (StackTrace ? stackTrace, int methodCount) {
244
+ String ? formatStackTrace (StackTrace ? stackTrace, int ? methodCount) {
231
245
List <String > lines = stackTrace
232
246
.toString ()
233
247
.split ('\n ' )
@@ -241,7 +255,9 @@ class PrettyPrinter extends LogPrinter {
241
255
.toList ();
242
256
List <String > formatted = [];
243
257
244
- for (int count = 0 ; count < min (lines.length, methodCount); count++ ) {
258
+ int stackTraceLength =
259
+ (methodCount != null ? min (lines.length, methodCount) : lines.length);
260
+ for (int count = 0 ; count < stackTraceLength; count++ ) {
245
261
var line = lines[count];
246
262
if (count < stackTraceBeginIndex) {
247
263
continue ;
0 commit comments