From 2af89aeb8b730b0ab5a35f95fd2582f9711c31d1 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 7 Nov 2022 10:40:02 +0100 Subject: [PATCH] feat: Allow converting of stacktraces in logs This makes it possible to print the correct stacktraces when using web. --- lib/src/utils/logs.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/src/utils/logs.dart b/lib/src/utils/logs.dart index 8c509899..628e6d55 100644 --- a/lib/src/utils/logs.dart +++ b/lib/src/utils/logs.dart @@ -35,6 +35,10 @@ enum Level { class Logs { static final Logs _singleton = Logs._internal(); + /// Override this function if you want to convert a stacktrace for some reason + /// for example to apply a source map in the browser. + static StackTrace? Function(StackTrace?) stackTraceConverter = (s) => s; + factory Logs() { return _singleton; } @@ -58,7 +62,7 @@ class Logs { LogEvent( title, exception: exception, - stackTrace: stackTrace, + stackTrace: stackTraceConverter(stackTrace), level: Level.wtf, ), ); @@ -68,7 +72,7 @@ class Logs { LogEvent( title, exception: exception, - stackTrace: stackTrace, + stackTrace: stackTraceConverter(stackTrace), level: Level.error, ), ); @@ -78,7 +82,7 @@ class Logs { LogEvent( title, exception: exception, - stackTrace: stackTrace, + stackTrace: stackTraceConverter(stackTrace), level: Level.warning, ), ); @@ -88,7 +92,7 @@ class Logs { LogEvent( title, exception: exception, - stackTrace: stackTrace, + stackTrace: stackTraceConverter(stackTrace), level: Level.info, ), ); @@ -98,7 +102,7 @@ class Logs { LogEvent( title, exception: exception, - stackTrace: stackTrace, + stackTrace: stackTraceConverter(stackTrace), level: Level.debug, ), ); @@ -108,7 +112,7 @@ class Logs { LogEvent( title, exception: exception, - stackTrace: stackTrace, + stackTrace: stackTraceConverter(stackTrace), level: Level.verbose, ), );