Logging Attribute Access
00:00
Logging Attribute Access and Mutation. Sometimes you need to keep track of what your code does and how your programs flow. One way to do that in Python is to use logging
.
00:14 This module provides all the functionality that you would require for logging your code. It allows you to constantly watch the code and generate useful information about how it works.
00:26
If you ever need to keep track of how and when you access and mutate a given attribute, then you can take advantage of property()
for that, too.
00:37
Here, you first import logging
and define a basic configuration. Then you implement Circle
with a managed attribute .radius
.
01:04
The getter method generates log information every time you access .radius
in your code.
01:30
The setter method logs each mutation that you perform on .radius
and also logs those situations in which you get an error because of bad input data.
01:59
On-screen, you can see this logged version of Circle
in action.
02:17 Logging useful data from attribute access and mutation can help you debug your code. Logging can also help you identify sources of problematic data input, analyze the performance of your code, spot usage patterns, and more.
02:35 In the next section of the course, you’ll see how to manage the deletion of attributes.
Become a Member to join the conversation.