#100DaysOfCode in Python Transcripts
Chapter: Days 31-33: Logging
Lecture: Introduction to logging
Login or purchase this course to watch this video and the rest of the course contents.
0:00 Hey, this is Michael, and I'll be your guide for the next 3 days. And over those 3 days, we're going to talk about
0:07 recording the actions of your application, giving you insight into how your app is running, how users are using or misusing you code,
0:16 and even capturing crashes that might happen. So, if you run a website, and the user says, "Hey, your site crashed."
0:27 Here's a 500 server error page from Get Up, for example. If it crashes, what do you do? They say, "Well, I clicked this button, "and it just crashed."
0:38 Great, if you click the button and the button works, well, you're in a really tough place trying to reproduce that, unless you recorded
0:44 exactly what they did and exactly what went wrong. So we'll see with logging that that's super easy to do. So next time they call you up and say,
0:53 "Hey, something crashed," you can actually go look and see what happened, and that will give you a much better chance of, one, reproducing
0:59 what they did, and two, solving the problem. Let's take a look inside the log file for Talk Python training. So this is somewhat condensed.
1:08 This is one log file from one day, but it's compacted so you can see the different scenarios within it. And it's also edited to be anonymous.
1:17 We're actually keeping more information in our log files, but I don't want to share people's private information, so this is what we're going to get.
1:24 Now, if you look through here you'll see a couple of things. There's notices, there's errors. For example, here's a user action.
1:31 This particular user from that IP address has successfully logged in. You can see information about their browser, and their IP address, and the time,
1:39 and all that kind of stuff. We have some more user access. Here somebody's subscribed to get notified.
1:45 They basically gave us their email address and said, "Hey, mail me when there are new classes." Down here, our user happened to have logged out.
1:51 They were logged in, and they did some stuff, and now it looks like they're gone. They were running Windows 10, for example, with Firefox.
1:57 That's cool, so these are the types of things you might record, but we also have other interesting stuff.
2:02 For example, why is a search engine trying to search a authenticated only lecture page? So, for some reason, it's trying to go to this page.
2:13 Either it doesn't exist, or it's not allowed to get to it. But, for some reason, people's trying to get here.
2:19 So maybe we should go and figure out what's going on, either make that page accessible to Google,
2:24 or maybe we're linking to it in a way we probably shouldn't. Look at this appear, though, this is a little nefarious.
2:30 We see somebody coming in and trying to go to wplogin.php. That's WordPress log in. This page, this site, is not written in php,
2:41 it's definitely not WordPress, but here somebody's trying to get into it. And they're telling us that the user agent is Firefox 4.0.
2:48 That's unlikely, 'cause that's so old. Here we can see somebody's actually trying to break in. If we look carefully, they're doing
2:56 it again, and actually again. This happens all the time. People are just probing for known ways
3:02 to get into your site, get into your database, and so on. So knowing what is happening with your application, it's really important.
3:10 It might be obvious what the users are doing, maybe. It's really unlikely that it was obvious that people are trying hack it, that search engines
3:16 are trying to search hidden parts of it, things like that. So having this log information is really, really important,
3:22 and you'll see it's quite easy to add to our apps.