Hi, Alex here from rebeloper.com and welcome back to the channel and welcome
back to this tutorial series on DuckUI. SwiftUI in UIKit, well kind of
and today we are going to talk about logs.
Okay everybody! We are going to talk
about logs and why it is so important to use smart looking logs in
your projects where basically when you are going to build that out. I most often
use print statements, till I have created DLog and it's really awesome, I do have
a separate video on this besides DuckUI but I have added this to DuckUI and I
want to show you how easy and useful it is to log on our console. So what do we
use logging for? Well we are going to kind of lazy developers so we are kind
of tracking where our code is running. So let's see for instance in viewdidload
let's we usually not in the viewdidload but somewhere else
we just kind of print out some stuff like view did load indeed, okay and yeah
now we know that we are in here and yeah let's just build and run and see that
printed out in the log, okay. I'm just yeah and as you can see there we go.
Viewdidload indeed, okay. Now that is what we usually do we know that okay the
program has want you're here if there is some issue did occur or it didn't occur
that's what we use most commonly the log for and we use print statements but this
can be hidden in a lot of other logs that are printed out in the console.
So DLog to the rescue. Let me just delete this because it's kind of looks hideous
by now in my eyes and let's see let's add a single line. So it is pretty
straightforward. Yeah first of all make sure you have
added DuckUI to your cocoa pot if you haven't already done so if you don't
know go ahead and take a look at one of the first videos on this playlist, all
the links are down below. So coming back DLog, okay. It is pretty simple.
You don't even have to type DLog just type in log and a dot and then you
just let's say we want to have a new line or a line, ln, line and we
have these two parentheses and a dash like so because that basically
initializes this and in here we want to add always a string. So these are just a
few lines a few rules that you have to have. Now let's type in here, let's say
one, two, three just to make sure that we do have that log printed out in our
console. We should see it right here, okay. And it looks really, really nice. Let me
just make this a little bit larger, yep. One, two, three or let's see viewdidload.
We are in a viewdidload. Well let's say we want to have some other icons here
and they are believe me there are quite a few there and I just want to
show you just a few of them. Let's go into that set of views with safe area.
Let's log with success
and let's see inside setup views now. Okay and that is it. Let's hit command R
to see that in action, okay. Inside setup views now and viewdidload and now you
can I don't know which one comes first. Great, okay and as you can see here we
have some cool emojis or not emojis there are icons, okay. Now let's just jump into the
definition right away and see that we have a line, success, warning, error, to do
and the URL. Of course if you wanted to you could extend upon this but hey it's
up to you, okay. One thing to note is that you know print
statements are here and there but they take up memory of course and if you
wanted to have them show in the debug follow these four steps only. So that is
just it, so enable logs, go to the build settings other see flags enter this
debug for the debug flag, comment out this if and if stay lines and just
celebrate that's it and now you will be presented only with debug mode logic.
Okay, I won't do that because yeah kind of cannot test it but yeah it is memory
saver. Now there is one last thing that I want to talk about logging and that is
let me just move this up we don't really know inside set up views now or
viewdidload which class, where, when and that is where the DLogs
stats come in. Let me just type in here. let's add it like so maybe add like
that and the DLog and stats. So that's it
just add DLog stats into your log make sure that it needs to be inside here
because it's taking the reference of where it basically is called and that is
going to be printed out. So DLog dot stats
inside your log statement, okay. Let's build and run again and see how that looks, pretty
nice, pretty nice. Now let's deconstruct this if you can see inside setup views
now so that is what you already knew. We have that check mark so we do have that
icons what is this add. This means that we are on the main thread. June the first,
years that's one the date, time, rootview controller dot swift real nice, setup
views with safe area and the line 26 and the same goes the same data for our
viewdidload log statement. Now this is very, very good for debugging your code.
I can't tell you how awesome it is and you know even this M so we are on the main
thread but if we wanted to let's say after here and I will finish this
tutorial with this cone on the DispatcQueeHelper from da DuckUI also have a
tutorial on that so go ahead and take a look at some previous videos on the
DispatcQueeHelper. So we want to delay in a few seconds let's say after 3 seconds
and on the background thread. So here we go we are in the background and in the
completion, let's log, let's see let's log of an error.
Let's log an error here this warnings are so lame errors we want a huge error.
Okay and let's see. Let's add in here our
stats. So I just need to copy this out paste it and there and what should be
there let's see three seconds passed, okay. Maybe that's an error
that's three seconds have passed, okay. Let's build it run and see how that looks, okay.
We do have the first two and then we have that so we are not on the main
thread have of course and we are on the background thread so we do know and this
is important because sometimes when you fetch some data let's say an image from
server and you are displaying it on an image view and you are doing it, doing
that on the background thread that will not happen. So yeah it can take up to a
few seconds or all to display your image. So you are not on the background thread.
So now you know yeah and the same goes line 29 and the message that we have
added their three seconds passsed. So yeah that is DLog and how powerful it is
to log in and DuckUI. Of course if you did like this video you go ahead and
give it a thumbs up, subscribe to the channel and hit that notification bell
because even if you subscribe you might not get all of my new videos on your
feed and I hope you really want them to appear there so hit that notification
button and as always I will see you in the next one.