#100DaysOfCode in Python Transcripts
Chapter: Days 31-33: Logging
Lecture: Demo: Logging a the API level

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now we've logged at the general top level of our app, let's log down into our API interaction here. So let's do a couple things,
0:08 let's do some time tracking here so we'll import this. We'll do this time thing so we know how long this takes. So that'll give us a start
0:19 and end time we come down here and we say something like this api_log.trace we'll do some verbose things like "starting search for keyword"
0:33 and then let's put this bookend here, "finished search for keyword". Some results in some number seconds. Put colon g grouping, okay.
0:43 So what're we going to have? How many results? That's going to be len of movies and the duration is going to be t1 minus t0. So this is great.
0:54 We can also come down here and say api_log.warn("no keyword supplied") We could come down here and maybe store the status.
1:08 That's probably a traced type of thing. Request finished. There's our status code before we potentially throw in exception
1:19 so we know instead of 500 is it 404, things like that. Okay, I feel like this is pretty good, let's run it one more time and see if our app is ready.
1:27 So we started our logging, that's good. We're going to search for "test", see what do we get down here. API started the search for test.
1:34 The request finished, status code 200. That's good. And then it finished in this amount of time, that's seems like a huge weird number
1:41 so we'll do some clean up on that number and then it finished and it came over here. So, that's all pretty cool. Let's switch this to milliseconds
1:51 and do an integer times 1,000. One more to see how that works, quick test. There we go, that looks a little more clean to me.
2:01 193 milliseconds for our request, everything was good. Let's try some sort of error. Starting search for nothing, warning no thing.
2:11 Now noticed over here we have our API levels and we have our app level and we have our start up code. So it really tells you like
2:17 what part of your application is talking to you on this particular message. Alright, so I feel like we've pretty much
2:23 added really nice logging to our application. But we're not quiet done yet.


Talk Python's Mastodon Michael Kennedy's Mastodon