#100DaysOfCode in Python Transcripts
Chapter: Days 31-33: Logging
Lecture: Demo: File logging
Login or purchase this course to watch this video and the rest of the course contents.
0:00 So far, we've got this almost unreadable log goo mixed in with our standard user input/output. So it's really,
0:10 it's nice that we can see what's going on, but it's really not helpful for us here. So let's change this. Let's just go down here and, to our program,
0:21 and when we init the logging, instead of passing in nothing, we're going to pass in a file name,
0:25 and that's going to go to the timed rotating file handler, the same level rather than the standard out. Okay, so let's go down here, and let's,
0:33 we'll just call this movie app.log, something like this, and run it again. Alright, now it's back to the way it was before in terms of interactions.
0:46 There's none of that mess around. Let's search for action again. And it runs, and we get our nice output, and, ta-da! Let's run it one more time.
0:54 Let's search for hero. Ah, we got a bunch of good stuff with heroes and so on. And let's run it with an error. Nope, must search for something.
1:03 Alright, how about jazz. Anything there? Hmm, looks like there is. Pretty cool, so that's great. Our app is working again, but notice,
1:11 notice over here, we now have a movie-app. Instead of .log, it has 2018-02-23, because that's today, that's when I'm recording this
1:22 right now, so let's look and see what's in there. So you can see it's exactly the same messages. Here's the app is starting up.
1:29 Here's the app starting up again. Things like that, here's another startup. And these are all the messages.
1:35 We started a search for action, we got a 200. We got eight results, that long. Alright, and you can see the time of day
1:42 to the super accurate right there. Again, we're starting up, and this time we searched for hero and got 10 results. This time we searched for nothing,
1:50 and we got a warning, and so on. Okay, so we have this log file here, and it's not super important, it's less important, let's say, when you're writing
1:58 a regular app, 'cause you could just put the data and time in the log file. But if you're writing a super long running service,
2:05 like a web application that starts and runs basically indefinitely, or some kind of queuing application that's just listening
2:14 for messages and is going to run, basically anything on the server that starts and just runs, the ability to have it automatically rotate -
2:22 when it becomes the 24th, the next log message will just start a new file, for example. So really really nice to have this timed,
2:29 rotating file handler here.