#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,
0:02 let's log down into our API interaction here.
0:05 So let's do a couple things,
0:07 let's do some time tracking here
0:09 so we'll import this.
0:12 We'll do this time thing so we know how long this takes.
0:17 So that'll give us a start
0:18 and end time we come down here
0:20 and we say something like this api_log.trace
0:23 we'll do some verbose things
0:25 like "starting search for keyword"
0:32 and then let's put this bookend here,
0:33 "finished search for keyword".
0:37 Some results in some number seconds.
0:41 Put colon g grouping, okay.
0:42 So what're we going to have?
0:44 How many results? That's going to be len of movies
0:47 and the duration is going to be t1 minus t0.
0:51 So this is great.
0:53 We can also come down here
0:54 and say api_log.warn("no keyword supplied")
1:03 We could come down here and maybe store the status.
1:07 That's probably a traced type of thing.
1:10 Request finished.
1:16 There's our status code before
1:17 we potentially throw in exception
1:18 so we know instead of 500 is it 404, things like that.
1:22 Okay, I feel like this is pretty good,
1:23 let's run it one more time and see if our app is ready.
1:26 So we started our logging, that's good.
1:27 We're going to search for "test",
1:29 see what do we get down here.
1:30 API started the search for test.
1:33 The request finished, status code 200.
1:35 That's good.
1:36 And then it finished in this amount of time,
1:38 that's seems like a huge weird number
1:40 so we'll do some clean up on that number
1:42 and then it finished and it came over here.
1:44 So, that's all pretty cool.
1:46 Let's switch this to milliseconds
1:50 and do an integer times 1,000.
1:55 One more to see how that works, quick test.
1:57 There we go, that looks a little more clean to me.
2:00 193 milliseconds for our request, everything was good.
2:04 Let's try some sort of error.
2:06 Starting search for nothing, warning no thing.
2:10 Now noticed over here we have our API levels
2:12 and we have our app level and we have our start up code.
2:15 So it really tells you like
2:16 what part of your application is talking
2:18 to you on this particular message.
2:21 Alright, so I feel like we've pretty much
2:22 added really nice logging to our application.
2:25 But we're not quiet done yet.