Flutter Logging - A Guide on How to Use it Effectively
Вставка
- Опубліковано 5 лип 2024
- Written tutorial: www.filledstacks.com/post/flu...
Tutorial Source: github.com/FilledStacks/flutt...
Code to download: firebasestorage.googleapis.co... - Наука та технологія
Thanks! I've been struggling with debugging. The written guide and this video make logging in Flutter crystal clear!
Awesome man!! That's exactly what I was hoping for. I'm happy to have helped :)
As IceCube once said of logging: Warn yo self, before you wreck yo self!
hahaha, he does often say that 😅 Always here so early. You da best! 🤩
@@FilledStacks Don't mind me, just passing through, hunting for quality flutter content, it just so happens that you have it 🙃
🙌 ☺️
Thanks I much learned from your blog and this channel. Awesome!
I'm waiting tutorial for handle paging or infinite scroll over rest api using provider/bloc with future builder.
Awesome man! I might do a video on that but I won't use a Future builder. The model would collect the data and concatenate the list. We'll call notifyListeners when the list has been updated.
No one :
FilledStacks : *Lets create a new file*
That's how it goes.
Thanks a lot, very helpful package and wonderful explanation as ever. I would really like you to do a video on setting up multiple flavors of the app in flutter.
Thanks for the feedback. It's not something very common at the moment and there are some community articles on it already (cogitas.net/creating-flavors-of-a-flutter-app/) I usually do branding through my source control using branches per product flavour instead of cluttering the code with all that logic.
Really helpful thanks
😊 I'm happy to help
Sho', really good stuff here...thank you...maybe one suggestion would be to contribute to the Flutter or the Dart logger and provide your logger flavour as a solid implementation so the whole community could profit from it. Just a suggestion. One other suggestion would be for a dependecy injection for logging of the entry to a function...hardcoding it would be a maintenance overhead especially if the codebase is large. Not sure about the latter, since I am a Go/Java programmer and new to Dart/Flutter. In other words it would be great to be able to configure a Dependency Injection of a logger so that one could trace the calls. Even better would be to be able to switch it on and off again. Lastly, for Production code, what is the overhead for logging...okay i think i have veered a little off topic here.
Thanks, happy you found some value in it. The most I would probably do is create a package that contains the 6 lines of code for the logger as an extension but I don't think they'd accept my specific logging format as a default option. There are definitely ways to automatically log some stuff. Maybe when I get some time I can write up the code for that and release it as a LogPrinter extension package.
Great video. Reminds me of Log4J and how cool that was at creating your own 'pretty printers'. One question - on VS CODE, how did you get your colours to display - I'm getting ascii codes being shown in the debug console so I'm guessing it might be a special installed font you are using ?
Hi Stella, thanks for the feedback. I will assume you're on a Mac. After releasing the video i realised that many devs are not seeing the colors show up and they were all on Mac. There's been issues filed on the repo. Or someone contacted the dev, can't remember which way it went but he's working on it. If you're not on Mac then ignore all that 😅 I didn't install anything special. Default powershell terminal shows the colors for me.
thanks for the video, coming from fireship. this channel worth subscribing.
Thanks a lot. That's a huge compliment man. Much appreciated, I'm a big fan of the Fireship videos myself.
I'm starting to like your channel. very very good contents and lots of advanced topics.. Do you have an example of properly using Logger for Errors? I wish you have a snippet for it
I do have a Logging tutorial. It gives a run down of when to log and what to log to make sense of any error that happens in the code.
Hello excellent as always. How do you advice to instantiate "log" variable if I have more than one class in the same dart file?
The same way. A log per class. Simply call getLogger in the class
Great work as always! The package now is updated to 0.8.0 so its not possible to create the SimpleLogPrinter extended class as you did. But I adapted and gave you credit here in this github issue on the Logger repo. github.com/leisim/logger/issues/31
So for those who are willing how to customize your loggers with colors and emojis like @FilledStacks did, just click the link and copy the example.
Cheers and happy coding!
Thank you for your help!
Thanks for sharing! That's pretty cool, I'll check it out.
Hi, should I include logs in released version of my app or flutter just ignore those print and log statements while building release apk to reserve app size just code itself???
I do, especially when I've hooked up remote logging or logging to a file. If you're not doing that then you you can wrap your SimpleLogPrinter print code in an assert(() { /* log code here*/ }). Assert will only run in debug mode. Then you can add logger as a dev_dependency in your pubspec and not a full dependency.
@@FilledStacks How do you log to file, im struggling ith this, can yo uplease send me some tutorials.
@@dharmendrapandey2668 Hey, I don't have tutorials for that but I would add it in as a LogOutput which will use an queue to internally write out all the logs in order on a separate thread.
Thanks for the video. How do we see these logs in production after deploying in Android or IOS platforms?
You're welcome. We use Google cloud logging. You can add an addition log ouput that writes to cloud logging then you can look at the logs on there.
With the logging package, are they saved between launches? If so, is it possible to adb retrieve the logs after a bit?
No, nothing is saved. You'll have to add your own logging output and save to disk. Then you'll be able to retrieve it after a run
Thanks for saving my time. I've a question, how can I get logs from a live app running on users device with firebase as backend.
You should use Cloud Logging and wrap it in a service. Then you can create an additional LogOutput and when the log functio is called you send it to your Cloud Logging service.
@@FilledStacks Great, thanks for quick info.
if we use autogenerate route where do we put the code to track user activity since there is no genarate route function available
You can add it as a navigation observer in the Material app. it passes you the route that it's going to so you can log it out.
Is there any way those logs that you print to save em in a txt file ? Or any file type in the internal memory ?
Thanks
Yes, the logger package takes a LogOutput. You can build your own one which writes to a file. If you read the docs you'll see the options for it there.
Thanks for the reply 💪 I will look into it
@@gregorysamaras7919 :)
nice
💪
Can you please cover how to log this in a file and how to send it to server for reporting.
Hey, yes. I'll write a tutorial on the cloud logging we use and also build a file output if needed for your other requirement. Don't know when, but it's been on my list of videos.
LOL there is a level called "wtf" 4:49
hahaha yeeaaah, you get those moments in code where that's helpful 😂
That's actually 'What a terrible failure' level
Source of code dont exists
Yeah there's no source code for this. In the written you'll see it's just a few lines of code in one file so there's no need for having source code for it.
what did you eat to be good in oop?
🥝🥥🌶🍇🍩🍣 🍝
I need something like this sample in OOP. Can you provide a tutorial like this too? Real world sample
@@jajasaria This is tutorial is a real world example for Object oriented programming. Flutter is written in dart which is an Object oriented programming (OOP) language. All my tutorials are for real world examples. Logging depends on what you want to log. I'm just giving some general guidelines for logging. You can additional logs to what you know is important to your app.
@@FilledStacks yes i understand. what im saying is a tutorial more focus in OOP (Dart Programming) using realworld example like this one. The way you explain things is so amazing and i like it. thanks to this
@@jajasaria Thanks. I won't be covering anything around programming topics, I'd like to focus on concepts where you require programming knowledge. The reason I started making videos is because I couldn't find any practical guides to architecture or how to structure your code in general. No one talks about code separation, everyone is making videos for beginners so I'm sure you can find some very nice beginner OOP videos / courses out there. I'll stay focused on the real world side. Everything I've been showing is code principles that make OOP better, so in a sense these are all Object oriented programming tutorials.