@@ -74,25 +74,33 @@ class PrettyPrinter extends LogPrinter {
7474 /// * [excludePaths]
7575 final int stackTraceBeginIndex;
7676
77- /// Controls the method count in created stack traces.
77+ /// Controls the method count in stack traces
78+ /// when no [LogEvent.error] was provided.
7879 ///
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.
8082 ///
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.
8286 ///
8387 /// See also:
8488 /// * [errorMethodCount]
85- final int methodCount;
89+ final int ? methodCount;
8690
87- /// Controls the method count in provided stack traces.
91+ /// Controls the method count in stack traces
92+ /// when [LogEvent.error] was provided.
8893 ///
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.
9096 ///
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.
92100 ///
93101 /// See also:
94102 /// * [methodCount]
95- final int errorMethodCount;
103+ final int ? errorMethodCount;
96104
97105 /// Controls the length of the divider lines.
98106 final int lineLength;
@@ -203,12 +211,18 @@ class PrettyPrinter extends LogPrinter {
203211 var messageStr = stringifyMessage (event.message);
204212
205213 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+ );
209220 }
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+ );
212226 }
213227
214228 var errorStr = event.error? .toString ();
@@ -227,7 +241,7 @@ class PrettyPrinter extends LogPrinter {
227241 );
228242 }
229243
230- String ? formatStackTrace (StackTrace ? stackTrace, int methodCount) {
244+ String ? formatStackTrace (StackTrace ? stackTrace, int ? methodCount) {
231245 List <String > lines = stackTrace
232246 .toString ()
233247 .split ('\n ' )
@@ -241,7 +255,9 @@ class PrettyPrinter extends LogPrinter {
241255 .toList ();
242256 List <String > formatted = [];
243257
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++ ) {
245261 var line = lines[count];
246262 if (count < stackTraceBeginIndex) {
247263 continue ;
0 commit comments