react-native-logs icon indicating copy to clipboard operation
react-native-logs copied to clipboard

Doesn't print line number or file name

Open yehyaumar opened this issue 2 years ago • 3 comments

When logging, it doesn't show the line number or file name of the log. Instead it shows this consoleTransport.js:40 when logging. How to print the line number and file name with this logger?

yehyaumar avatar Oct 20 '21 05:10 yehyaumar

I really like the color but I like to see where that log come from and link me to it image instead that, react-native-logs link me to the consoleTransport.js:46

janet-rivas avatar Apr 11 '22 15:04 janet-rivas

I am not sure this is possible. The console reader prints the line the log statement was issued and that should be a problem for all JS logging solutions. And even if there would be a way to specify the source file and line number, one would have to still find this out. Since you have no source information at runtime accessible one would have to create a temp exception, catch it, inspect its callstack and extract a couple of lines back from it to find the source of call.

But I think the best way is to modify the console transport to use console.info.bind(console, timestamp, level, msg). That way the line number should be the one of the caller.

This would all be easier, if this library would just patch console.log functions in the first place and add the transports on top of that. This would also be a drop-in replacement for already existing console.log etc calls in apps sources. See #61

pke avatar May 04 '22 07:05 pke

Even doing the bind to console or try to parse an error stack, react-native creates a js bundle that makes it impossible to trace back to the right file and line number. We need to work on source-maps, as I believe expo logs do. for now I'll leave the issue open until a fairly simple solution is found.

alessandro-bottamedi avatar Jun 30 '22 13:06 alessandro-bottamedi