Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Logging user and system activity
Lecture: Integration markdown-subtemplate and LogBook

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now, if you really care about this mark down sub template logging stuff and you're using some logging system, the only reasonable thing to do probably is to put them together.
0:08 So let's just really quickly do that.
0:10 And as we saw over here in our storage engine, what we did is created a class that drive from something in storage.
0:16 Well, it's gonna be really similar over here or Logan, and there's a bunch of stuff we're not gonna need. So let's clean this up here.
0:24 This is gonna be logging. I would have to import that.
0:28 I did want to give us to help their so from markdowns, sub templates, import logging, I'll say logging sub template longer.
0:38 It Let's get rid of all of this stuff here and for a moment, all right past.
0:43 But what I really want to do is implement these four methods that we have to dio in order for us to rightto logbook just like we were over in all the other places.
0:52 Like over here to do that. What we did is we created one of these little logs.
0:57 I'm gonna do that up here as well, and this is gonna be mark down something like that. And you know what? This is super super easy.
1:07 So we go look at this thing it's going to have when you create it, you're gonna have to pass over the log level and it's gonna store it.
1:13 But we don't have to really do any defining different than that. So we're just gonna hang on to it like this, and then we'll just say really quickly.
1:22 Now, the way it works is you need to check somehow whether or not you're at this right level.
1:27 So it has a built in should log, and we're gonna give it Ah, a couple of things. We're gonna give it the level in the log level that were asking.
1:36 Actually, it was a log level, however both so it knows what level it's at. And we're saying we're gonna consider to do a verbose logging.
1:46 Should we do that?
1:47 Given the level of your at the other thing, we want to pass along as text and you might wonder, like, what does the text have to do with it off the Texas empty?
1:54 We're not gonna write a log message for that. It will say if not this return. That's gonna happen at each one of these.
2:03 I don't really know of a better way to do that, Okay? And then we're just gonna really simply come down here and say log dot What's close to verbose?
2:12 Swell trace When I go and put out the text, You the markdown longer here. Like that. What about this one? Also trace. What about this one?
2:25 This is info. Logbook hasn't info level, and it has an air level. Okay. And that's it.
2:34 We've now integrated are marked on September system with our logbook integration just like before.
2:42 The only other thing we have to do is Member This part in the database where we initialize mark down. We came for the storage.
2:54 We're gonna say log already ever logging here. It looks like we do. Yeah, right there were already in it. Already.
3:01 Got that because we were playing with it before. Well, say logging, not get log. Sorry. Set log. And what do we want to set it to? That's it.
3:10 Log engine. Oh, I didn't rename that leads. Ah, call it longer some like that.
3:19 And we've got to import that and we need to pass in the level log level dot What level do we want to do it? Let's say we're going to do invoke.
3:28 I always had the log engine and that's it. We could also mark down logging engines set to engine. Perfect. Well, let's give it a shot.
3:40 See if this works. Okay? It's looking good. We have our notice. Notice notice here.
3:45 Actually, when we got to go and set that back here, let's go to Trace just for a moment, just to make sure we see the messages.
3:56 Okay, so let's see, We've set our markdown logging engine to sub template. Logger, if we make a request, notice a couple of things here.
4:09 We didn't have to generate that page because, yes, it was already created. See? Oh, I made a mistake over here.
4:18 You'll probably notice that you're like my go. What are you doing? This? We have to adjust. This level and that level have to match. So we say trace.
4:26 I say info and air. OK, now, now we should see some subways request. That's again. Perfect. Check this out.
4:34 So we've got an info level message from the markdown system that it generated this HTML.
4:41 And then our controller also has this message here and noticed that it this part and this part these are all going through the logbook output.
4:50 So this way, if we set up file logging or routine violence, whatever the messages coming out of the markdown sub template will also show up over there.
5:00 So we visit any of these you should see. Now we're generating the markdown for this.
5:04 If we visited again, or refresh it again, we won't see the markdown out, but because we're using, cashing or not regenerated it.
5:11 But we are really requesting it over here. Perfect, right.
5:15 Okay, well, it depends on what you're doing, whether or not this step is necessary or helpful to you.
5:20 But if you're using a custom logging framework like logbook, which I recommend, look, it's super easy to add it here and just fold all these things together and just get a little more information about how your APs running.
5:32 And that's got to be good to help you keep it running correctly and be able to diagnose stuff that goes wrong.


Talk Python's Mastodon Michael Kennedy's Mastodon