get_it icon indicating copy to clipboard operation
get_it copied to clipboard

Ability to log lifecycle changes

Open jokilic opened this issue 1 year ago • 6 comments

I would love to be able to track lifecycle changes of classes I instantiate using GetIt or WatchIt. Something like an observer which can be passed to ProviderScope in Riverpod.

So I can log when some class is instantated, disposed, etc.

jokilic avatar Jan 16 '25 20:01 jokilic

Can you elaborate this a bit more? I'm not sure how for what you would use this?

escamoteur avatar Jan 23 '25 09:01 escamoteur

It's used so I can have information about initialization and disposal of various classes in the console. It's something like a BlocObserver which you can check HERE.

I would like this global 'observer' where I can set that it logs someting like this when it initializes a class with GetIt: ✅ $className INITIALIZED ✅

And when it disposes, I would log something like this: ❌ $className DISPOSED ❌

Does all this make sense?

jokilic avatar Jan 24 '25 16:01 jokilic

Adding logging for creation of instances inside get_it like from factories or lazy simpletons or any dependent singletons would be possible but because objects are not always actively disposed the question would be should it be logged if a dispose was called on a registered object? Or if the instance was removed from get_it. Even then we won't know if the object will get garbage collected because there could be another reference.

Whatndo you think makes here the most sense? Am 24. Jan. 2025, 17:45 +0100 schrieb Josip K @.***>:

It's used so I can have information about initialization and disposal of various classes in the console. It's something like a BlocObserver which you can check HERE. I would like this global 'observer' where I can set that it logs someting like this when it initializes a class with GetIt: ✅ $className INITIALIZED ✅ And when it disposes, I would log something like this: ❌ $className DISPOSED ❌ Does all this make sense? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

escamoteur avatar Jan 25 '25 13:01 escamoteur

I would love to have the ability to log when instances get created and when they get disposed. Whatever the reason for disposal is, logging would help me get a better understanding of the lifecycle and general behaviour of instances within my app.

So yeah, adding the ability to use somekind of a global observer would be a cool feature for GetIt and WatchIt. Of course, if the developer doesn't add anything, it will behave without any logs or whatever.

But yeah, having the ability to add a global observer would help me a lot (and others, I'm sure).

jokilic avatar Jan 25 '25 16:01 jokilic

The biggest problem is that there is no guaranted disposal but I agree it could be very helpful

escamoteur avatar Jul 18 '25 03:07 escamoteur

+1 I would love to see this

ryanhanks-bestow avatar Oct 31 '25 11:10 ryanhanks-bestow