Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Logging user and system activity
Lecture: Demo: A tour of the existing logging
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
here we are in our Chapter 11 copy of our web app. And I won't just take you on a quick tour of what we got to work with here.
0:08
So I've added this logging function. Here's that initialize is logbooks over the top we've installed and then imported logbook.
0:17
And then down here, we're just gonna go and sell logbook. Teoh, push to standard out.
0:22
That's like the same is just doing a print when you go to production.
0:26
If you really run this on real servers, obviously that's not gonna help you a lot. So you're gonna want to set this up toe log to a file.
0:32
Just check out the logbook documentation. It's super easy to have rotating file systems while handling there. We're going to set that up globally once.
0:41
And then any time you want, we could create one of these things and give it a name like APP or CMS or admin or whatever.
0:48
So what about these little different levels? Right? Weaken set the level of our logging right now it's on log. Everything.
0:56
But we could say Onley log like warnings and above. And then this notice would not actually appear. Okay, So that's one of the features.
1:03
That's pretty cool.
1:05
It wouldn't go down here when initialized just say, Hey, we initialize the logging and then for mark down, we're going to say what storage engine we put in here down to the bottom.
1:14
We're gonna say how many Web routes we've registered and then what? Whether or not we're initialized in the database.
1:21
This one we've also remember we had a print statement right here, and we've changed that to now log, this will right now go to print basically the same.
1:30
But what's really nice is it will go to the file system when we if we ever switch it to that. So for over here we're just creating a DB session logger.
1:39
We also have in the admin section, appear a seem with this should be called ad Mention it Rio.
1:46
So we have an admin section down here and you'll see at the bottom when we're, say, working with a redirect.
1:54
It'll say the user so and so is adding or updating a redirect. And then after it succeeds, it says they've added or updated.
2:01
We're not really distinguishing right. Member of this function is used for both. And this is just trace. Like maybe maybe it should be higher notice.
2:09
What do you think this is? People making changes through the site Traces? Probably a little low. Got the other one. Appears this trace as well.
2:18
That's good, but that I also did some places where Trace makes more sense. Let's look over at our CMS controller.
2:27
And over this one, we probably want to do the same thing. So we could say log equals log book.
2:31
And we have to import that logger, and this one could be CMS.
2:36
And then down here, we could just have a message for, say, log dot This one you definitely wanna be traced. Like every page we're going to tell you.
2:42
This page was requested.
2:44
Well, only in, like, super tell me everything mode and we want to see that That we could say, Ah CMS request Get the title or something like that.
2:59
Greek for redirect for the short your l And then we could also get in here. Maybe make this a little bit higher. CMS request not found.
3:15
Put the oil there. Okay, let's give this a shot. See how it's working.
3:19
And I noticed what it runs Now we've got the date, the time, the level of the message. Loggins initialized.
3:27
This order trades for the DB session, initializing right initial light that it's going to initialize and we'll see this even if you re initialize it.
3:35
So that's why this trace but notice. Here's where we're actually connecting to once and only once.
3:40
Here's the app starting up over here and then go to our admin section and now admin trace user impunity viewing. Advent home.
3:52
They're viewing the page list. I go over here and edit it.
3:59
Let's say make no real changes now these air notices the user impunity was updating the page.
4:07
It was our team at this address, and then we're back looking a list That's pretty cool.
4:13
And then finally, if we hit a page here like this, there's a couple of things that are cool. One.
4:18
We're doing a Seamus Requests or this title this page. Maybe the euro should be involved, possibly. But notice here.
4:26
This is from the markdown sub templates, and it's even though it has the square brackets, so it kind of looks the same. It's not the same right.
4:33
It's not coming through this system And how can I show you that lets I've made it a little more obvious If we go down here to this logging thing, we don't set up this standard out longer notice.
4:46
All those messages are gone. They're just going basically to nowhere right, logbooks like I've got a message nowhere to put it. So throw it away.
4:54
Right. And if we go look at this page, notice these air still getting generated right to the ideas.
5:00
Like if we set in that to a file, these would not go. That file is to just go to standard out. So So that's not ideal.
5:07
What we want to dio also to forward it sort of round this out if we want to take the logging coming out of our markdown subsystem said it to a certain level.
5:15
So we control that and then also put Push that out, too. Are logbook integration.
5:22
But for starters, it's cool to just see that we've got super super simple logging integrated into our system.
5:30
We just change it right here to go to a different place. Like to get it to go to ah rotating file or something like that. Pretty easy, huh? I love log