Python for Entrepreneurs Transcripts
Chapter: Monitoring and logging in production
Lecture: Introducing logbook: better logging than builtins
Login or purchase this course to watch this video and the rest of the course contents.
0:03 Welcome to level one, logging. So here is a log file from Talk Python Training, I've edited it down for a couple of things, condense some information
0:15 to remove things like usernames or email addresses and whatnot, but this is more or less what comes off of the server.
0:22 And, here I want to highlight a couple of things we can learn about this log, in fact, I learned a few things even just looking at it
0:30 for this presentation, so hey, that's pretty cool. Alright. now let's start with user actions, so here you can see
0:36 I've specifically added login information to the account controller to the purchase controller, things like that.
0:46 So you can see here, here is a case where a user successfully logged in to the app
0:50 and coming back to the class, thank you, whoever that is, that's awesome. They can also see over here that somebody who is not yet a user
0:58 has come to the website and they filled out that Mailchimp newsletter form right on the front page that says "hey I am not ready to buy class yet
1:05 but some of the stuff on your list looks really cool, just let me know when it's finished", so they enter their email address,
1:09 and they subscribed to the mailing list, also very cool, thank you. And down here, you can see somebody has logged out,
1:17 so in my actual logs I have the username and email address just so I can sort of corelate that back to who these people are,
1:24 but of course, I don't really want to violate their privacy. So I took that out, but you can add these actions, so you see "oh, cool,
1:31 people are using my web app in this way". We can also see things like search engines, so down here you can see some kind of search engine is trying
1:41 to actually get to the lecture 52018 from this course. Well, that search engine didn't buy access to that course
1:50 so I am not letting them in, I am actually not sure where that is coming from,
1:54 and that's one of the things I am learning, I tweaked my sitemap a little bit and I am not really sure how it got here so I am going to look into this,
2:03 but nonetheless, you can see what search engines are up to, and you can even see what hackers are up to, and let me just tell you,
2:10 if you have a website on the internet, it is constantly under attack, you put a website up, it gets a little bit popular,
2:19 you'll be blown away at like how many hack attempts are on it. So, here we can see that somebody is trying to look and see
2:28 if I am running a Wordpress site, and if I am they are going to then flip over,
2:33 they are trying to load the login page and then they are going to start dictionary attacking it or using default passwords or something like that.
2:41 So you are "oh my god, someone is hacking my site", yeah, they do it, all the time.
2:46 So, you just have to make sure that you have your security story down, you have to make sure that your website is patched,
2:54 do that in Linux or whatever right, behind the scenes and make sure it's patched,
2:58 make sure that all your dependencies like Pyramid stuff are up to date, like you need to be super vigilant because you can see
3:05 even in just the simple set of logs here, people are hacking way on it, and these are just the ones that went to places that were not found, right,
3:14 who knows what else is they are doing that I haven't put logging in for. So the big question is "how do I generate this log"?
3:22 Python itself has logging built in, but I want to show you something that I think is a pretty significant improvement over Python's default logging.
3:32 And that is Logbook. So Logbook is a package put together by Armin Ronacher, Armin Ronacher is the guy behind Flask so you know this is solid software,
3:42 and you can see from this little welcome to Logbook "hello world" example
3:46 that it's very simple to get started, you'll see that it's nice to compose these across different layers of our application, lots of good stuff, OK.
3:56 So over the next couple of videos, we're going to be introducing Logbook
4:00 adding Logbook to our web application, and logging a couple of types of information,
4:05 application startup and some of the requests, like you saw in that previous screen.