magillus / flutter-fimber

Fimber is Flutter logger inspired by Timber (logger API for Android)
106 stars 22 forks source link

Retrieve logging history #49

Closed sterrenb closed 5 years ago

sterrenb commented 5 years ago

I'm using Fimber for logging in an app that interacts with a REST API. To allow easy troubleshooting on the client side, I would like to show recent logging messages on the frontend (e.g. in a ListView).

Would it possible to retrieve messages from a static method in the Fimber library? Perhaps the method could return something along the lines of a List<FimberLogObject>.

magillus commented 5 years ago

Hi, thank you for using Fimber. I assume you use it in Flutter project, currently that is not possible, logs with DebugTree or FimberTree (for Flutter) are outputted as normal console output - for iOS uses console print and for Android it uses Log.x calls. As far as I know on Android there is logcat command to run to fetch those and it would only get last X kB of logs (where X is device/OS specific).

One way to do it would be to create our own DebugTree and override printLog method to store it in database or a file, storing to file is done with other Fimber provided "trees" - SizeRollingFileTree, TimedRollingFileTree or FimberFileTree. Do you use those File loggers?

Check AssertTree for simple storing in memory of recent log lines - it is located in fimber_test.dart You can add a limit to 1000 lines stored, just to keep track of last of them.