#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
0:04 mixed in with our standard user input/output.
0:07 So it's really,
0:09 it's nice that we can see what's going on,
0:11 but it's really not helpful for us here.
0:13 So let's change this.
0:15 Let's just go down here and, to our program,
0:20 and when we init the logging, instead of passing in nothing,
0:22 we're going to pass in a file name,
0:24 and that's going to go to the timed rotating file handler,
0:28 the same level rather than the standard out.
0:31 Okay, so let's go down here, and let's,
0:32 we'll just call this movie app.log, something like this,
0:39 and run it again.
0:41 Alright, now it's back to the way it was before
0:43 in terms of interactions.
0:45 There's none of that mess around.
0:46 Let's search for action again.
0:49 And it runs, and we get our nice output, and, ta-da!
0:52 Let's run it one more time.
0:53 Let's search for hero.
0:55 Ah, we got a bunch of good stuff with heroes and so on.
0:58 And let's run it with an error.
1:00 Nope, must search for something.
1:02 Alright, how about jazz.
1:04 Anything there? Hmm, looks like there is.
1:06 Pretty cool, so that's great.
1:08 Our app is working again, but notice,
1:10 notice over here, we now have a movie-app.
1:13 Instead of .log, it has 2018-02-23,
1:18 because that's today, that's when I'm recording this
1:21 right now, so let's look and see what's in there.
1:23 So you can see it's exactly the same messages.
1:25 Here's the app is starting up.
1:28 Here's the app starting up again.
1:31 Things like that, here's another startup.
1:33 And these are all the messages.
1:34 We started a search for action, we got a 200.
1:37 We got eight results, that long.
1:39 Alright, and you can see the time of day
1:41 to the super accurate right there.
1:44 Again, we're starting up, and this time we searched
1:46 for hero and got 10 results.
1:48 This time we searched for nothing,
1:49 and we got a warning, and so on.
1:51 Okay, so we have this log file here,
1:53 and it's not super important,
1:56 it's less important, let's say, when you're writing
1:57 a regular app, 'cause you could just put
1:59 the data and time in the log file.
2:01 But if you're writing a super long running service,
2:04 like a web application that starts and runs
2:07 basically indefinitely, or
2:09 some kind of queuing application that's just listening
2:13 for messages and is going to run,
2:15 basically anything on the server
2:16 that starts and just runs,
2:18 the ability to have it automatically rotate -
2:21 when it becomes the 24th, the next log message
2:24 will just start a new file, for example.
2:26 So really really nice to have this timed,
2:28 rotating file handler here.