dart-lang / stack_trace

A package for manipulating stack traces and printing them readably.
https://pub.dev/packages/stack_trace
BSD 3-Clause "New" or "Revised" License
129 stars 21 forks source link

How to get only the caller class link ? #116

Closed visign3d closed 1 month ago

visign3d commented 2 years ago

There is a someLoggerMethod(Trace.current().frames[1].member) , witch returns the caller function name. Is it a way to insert a caller class link too in console? with result like

message, callerFunction , lib/className.dart //class link underlined
osa1 commented 1 month ago

I'm assuming you mean file paths by "class link"?

The answer currently is no.

In principle this could be done as the information is there in the stack traces, at least when running in the VM:

#0      C.g (file:///usr/local/google/home/omersa/dart/sdk/test/test.dart:10:22)
#1      C.f (file:///usr/local/google/home/omersa/dart/sdk/test/test.dart:5:5)
#2      main (file:///usr/local/google/home/omersa/dart/sdk/test/test.dart:16:7)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

However in the browser the "file path" field would be null.

If you are deploying on the web, and you have the source maps (which both dart2js and dart2wasm generate by default), you can use source_map_stack_trace package which maps your stack frames to source locations.