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