title
Python Tutorial: Logging Advanced - Loggers, Handlers, and Formatters

description
In this Python Tutorial, we will be going over the some more advanced logging concepts. These will include loggers, handlers, and formatters. Let's get started. Basics Logging Video - https://youtu.be/-ARI4Cz-awo The code from this video can be found at: https://github.com/CoreyMSchafer/code_snippets/tree/master/Logging-Advanced ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Python

detail
{'title': 'Python Tutorial: Logging Advanced - Loggers, Handlers, and Formatters', 'heatmap': [{'end': 216.287, 'start': 202.498, 'weight': 0.718}, {'end': 303.433, 'start': 255.464, 'weight': 0.732}, {'end': 449.719, 'start': 425.287, 'weight': 0.706}, {'end': 476.797, 'start': 450.259, 'weight': 0.727}, {'end': 665.873, 'start': 617.854, 'weight': 0.826}, {'end': 866.802, 'start': 840.511, 'weight': 0.707}, {'end': 1021.053, 'start': 961.169, 'weight': 1}], 'summary': 'Tutorial on python logging and best practices covers loggers, handlers, basic configurations, and drawbacks of using the root logger, emphasizing the importance of configuring separate loggers. it also explains configuring separate loggers for modules and specific loggers in python, and demonstrates logging errors, including tracebacks and adding multiple handlers for improved logging flexibility and hierarchy.', 'chapters': [{'end': 303.433, 'segs': [{'end': 33.525, 'src': 'embed', 'start': 0.229, 'weight': 0, 'content': [{'end': 4.511, 'text': "Hey there, how's it going everybody? In this video, we're going to continue learning about logging in Python.", 'start': 0.229, 'duration': 4.282}, {'end': 7.593, 'text': "Now, if you haven't seen my previous video on basic logging,", 'start': 4.831, 'duration': 2.762}, {'end': 12.095, 'text': "then you're definitely going to want to make sure that you watch and understand that video before jumping into this one.", 'start': 7.593, 'duration': 4.502}, {'end': 17.037, 'text': "Now, in this video, we'll be learning about loggers, different handlers, and a couple of other things.", 'start': 12.515, 'duration': 4.522}, {'end': 18.698, 'text': "So let's go ahead and get started.", 'start': 17.337, 'duration': 1.361}, {'end': 24.581, 'text': "Okay, so if you watched my first video, then you'll see that I have the same two files here that I used in that video.", 'start': 19.178, 'duration': 5.403}, {'end': 33.525, 'text': "I have this super simple application with some short functions here, and it's basically where we left off in the previous logging video.", 'start': 24.981, 'duration': 8.544}], 'summary': 'Continuing python logging with focus on loggers, handlers, and more.', 'duration': 33.296, 'max_score': 0.229, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg229.jpg'}, {'end': 69.788, 'src': 'embed', 'start': 38.707, 'weight': 1, 'content': [{'end': 42.23, 'text': "The configuration is that we're logging to this sample log file.", 'start': 38.707, 'duration': 3.523}, {'end': 45.073, 'text': "We're setting the log level equal to debug.", 'start': 42.651, 'duration': 2.422}, {'end': 52.3, 'text': "In our format, we have a custom format here where we're using the time, the name of the logger, and the message.", 'start': 45.433, 'duration': 6.867}, {'end': 57.084, 'text': 'And then here at the bottom, we are logging out some statements using our logging.debug.', 'start': 52.86, 'duration': 4.224}, {'end': 63.807, 'text': 'Now, we have another module here in this employee class where we pretty much did the same thing.', 'start': 58.425, 'duration': 5.382}, {'end': 64.967, 'text': "We're importing logging.", 'start': 63.847, 'duration': 1.12}, {'end': 69.788, 'text': "We're setting up our logging with a file equal to employee.log.", 'start': 65.327, 'duration': 4.461}], 'summary': 'Configured logging to sample and employee log files with debug level.', 'duration': 31.081, 'max_score': 38.707, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg38707.jpg'}, {'end': 167.648, 'src': 'embed', 'start': 127.435, 'weight': 2, 'content': [{'end': 132.518, 'text': "So I said in the last video that we'd discuss what this root message right here means.", 'start': 127.435, 'duration': 5.083}, {'end': 140.207, 'text': "And basically what this means is that since we haven't specified a specific logger, we're working with the root logger.", 'start': 133.058, 'duration': 7.149}, {'end': 145.994, 'text': "And this isn't necessarily a bad thing when working with smaller applications and specific files,", 'start': 140.567, 'duration': 5.427}, {'end': 151.381, 'text': "but it's best to get into the habit of logging to specific loggers that can all be configured separately.", 'start': 145.994, 'duration': 5.387}, {'end': 156.303, 'text': "Now we're going to take a look in just a second of how to get a specific logger.", 'start': 151.781, 'duration': 4.522}, {'end': 160.985, 'text': "But real quick, let me show you why working with this root logger isn't the best idea.", 'start': 156.783, 'duration': 4.202}, {'end': 166.007, 'text': 'So first, let me delete these employee and sample logs here.', 'start': 161.405, 'duration': 4.602}, {'end': 167.648, 'text': "So I'll delete that employee log.", 'start': 166.167, 'duration': 1.481}], 'summary': 'Discussion on using root logger and the importance of logging to specific loggers for separate configuration.', 'duration': 40.213, 'max_score': 127.435, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg127435.jpg'}, {'end': 231.978, 'src': 'heatmap', 'start': 202.498, 'weight': 0.718, 'content': [{'end': 206.681, 'text': "So now from this module where I'm importing employee, I'm going to go ahead and run this module.", 'start': 202.498, 'duration': 4.183}, {'end': 216.287, 'text': "Now we can see in our file system that it created this employee.log file, but our sample log file that we specified here isn't there.", 'start': 207.281, 'duration': 9.006}, {'end': 222.772, 'text': 'And if I open up my employee log file, we can see that it only logged out our created employees.', 'start': 216.808, 'duration': 5.964}, {'end': 224.593, 'text': 'So what happened here?', 'start': 223.592, 'duration': 1.001}, {'end': 231.978, 'text': "Why didn't this file create its log, its sample log, or execute these log statements down here at the bottom??", 'start': 224.673, 'duration': 7.305}], 'summary': 'Module created employee.log, but did not log sample data as expected.', 'duration': 29.48, 'max_score': 202.498, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg202498.jpg'}, {'end': 303.433, 'src': 'heatmap', 'start': 255.464, 'weight': 0.732, 'content': [{'end': 262.85, 'text': 'So by the time we get to configuring our logging within this script, the root logger is already configured with those other values,', 'start': 255.464, 'duration': 7.386}, {'end': 264.452, 'text': "so this doesn't actually do anything.", 'start': 262.85, 'duration': 1.602}, {'end': 267.715, 'text': "It doesn't overwrite those initial configurations.", 'start': 264.932, 'duration': 2.783}, {'end': 277.403, 'text': "Now, the only reason our log statements aren't logging down here at the bottom is because the root logger got set to that info level within the employee module.", 'start': 268.135, 'duration': 9.268}, {'end': 279.245, 'text': "so debug doesn't hit that level.", 'start': 277.403, 'duration': 1.842}, {'end': 286.393, 'text': 'Now if we were to change these here to info statements and I was to rerun that now.', 'start': 279.705, 'duration': 6.688}, {'end': 294.744, 'text': 'if I pull up this employee log file, then you can see that it did log the information from that script.', 'start': 286.393, 'duration': 8.351}, {'end': 296.285, 'text': 'that has the calculation functions.', 'start': 294.744, 'duration': 1.541}, {'end': 303.433, 'text': "But still, even though we did get those to log somewhere, this is still kind of a mess that we're sharing this root logger.", 'start': 296.806, 'duration': 6.627}], 'summary': "Configuring logging within script doesn't overwrite root logger; changing log level allows logging info from script.", 'duration': 47.969, 'max_score': 255.464, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg255464.jpg'}, {'end': 294.744, 'src': 'embed', 'start': 264.932, 'weight': 4, 'content': [{'end': 267.715, 'text': "It doesn't overwrite those initial configurations.", 'start': 264.932, 'duration': 2.783}, {'end': 277.403, 'text': "Now, the only reason our log statements aren't logging down here at the bottom is because the root logger got set to that info level within the employee module.", 'start': 268.135, 'duration': 9.268}, {'end': 279.245, 'text': "so debug doesn't hit that level.", 'start': 277.403, 'duration': 1.842}, {'end': 286.393, 'text': 'Now if we were to change these here to info statements and I was to rerun that now.', 'start': 279.705, 'duration': 6.688}, {'end': 294.744, 'text': 'if I pull up this employee log file, then you can see that it did log the information from that script.', 'start': 286.393, 'duration': 8.351}], 'summary': 'Initial configurations not overwritten, root logger set to info level, info statements logged in employee log file.', 'duration': 29.812, 'max_score': 264.932, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg264932.jpg'}], 'start': 0.229, 'title': 'Python logging and best practices', 'summary': 'Covers loggers, handlers, basic configurations, log files, log levels, custom formatting, and the drawbacks of using the root logger, emphasizing the importance of configuring separate loggers to avoid incomplete logging and conflicting configurations.', 'chapters': [{'end': 145.994, 'start': 0.229, 'title': 'Python logging: loggers and handlers', 'summary': 'Discusses loggers, handlers, and basic configurations in python logging, covering the usage of log files, log levels, and custom formatting.', 'duration': 145.765, 'highlights': ['The video covers loggers, handlers, and basic configurations in Python logging The chapter revolves around discussing loggers, handlers, and basic configurations in Python logging.', 'The usage of log files, log levels, and custom formatting is demonstrated Demonstrates the usage of log files, log levels, and custom formatting in Python logging.', 'Explanation of the root logger and its significance when working with smaller applications and specific files Explains the significance of the root logger when working with smaller applications and specific files.']}, {'end': 303.433, 'start': 145.994, 'title': 'Logging best practices', 'summary': 'Discusses the drawbacks of using the root logger for logging and highlights the importance of configuring separate loggers, as demonstrated by the issues encountered when sharing the root logger, resulting in incomplete logging and conflicting configurations.', 'duration': 157.439, 'highlights': ['When importing a module, the code from that module is executed, leading to the creation of the employee.log file and the absence of the specified sample log file, demonstrating the impact of root logger configuration on logging functionality.', "Configuring separate loggers is crucial as sharing the root logger can lead to conflicting configurations and incomplete logging, as evidenced by the inability to execute log statements and the impact of the root logger's log level on logging functionality.", 'Changing log statements to info level allows them to log the information, highlighting the impact of logger configuration on the logging output.']}], 'duration': 303.204, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg229.jpg', 'highlights': ['Covers loggers, handlers, and basic configurations in Python logging.', 'Demonstrates the usage of log files, log levels, and custom formatting in Python logging.', 'Explains the significance of the root logger when working with smaller applications and specific files.', 'Configuring separate loggers is crucial to avoid conflicting configurations and incomplete logging.', 'Changing log statements to info level allows them to log the information, highlighting the impact of logger configuration on the logging output.']}, {'end': 936.724, 'segs': [{'end': 346.317, 'src': 'embed', 'start': 303.753, 'weight': 0, 'content': [{'end': 309.84, 'text': "We're not getting the log file that we want, we're not getting the log levels that we want, and we're not getting the formatting that we want.", 'start': 303.753, 'duration': 6.087}, {'end': 315.206, 'text': "So let's get a new logger for each of our modules so that we can configure both of them separately.", 'start': 310.26, 'duration': 4.946}, {'end': 318.029, 'text': "So I'm going to go ahead and close this log file down.", 'start': 315.866, 'duration': 2.163}, {'end': 323.836, 'text': "And within the employee module here, I'm going to create a logger variable.", 'start': 318.57, 'duration': 5.266}, {'end': 327.12, 'text': "And I'll just do this above our configuration here.", 'start': 324.016, 'duration': 3.104}, {'end': 329.362, 'text': "So I'll say logger equals.", 'start': 327.14, 'duration': 2.222}, {'end': 333.687, 'text': "Now to get a new logger, I'm going to say logging.getlogger.", 'start': 329.783, 'duration': 3.904}, {'end': 336.269, 'text': 'And now we need to specify a name here.', 'start': 334.528, 'duration': 1.741}, {'end': 339.071, 'text': 'Now I could hard code any name here that I want,', 'start': 336.429, 'duration': 2.642}, {'end': 345.957, 'text': 'but a convention when naming loggers is to use this special double underscore name method or variable.', 'start': 339.071, 'duration': 6.886}, {'end': 346.317, 'text': "I'm sorry.", 'start': 345.957, 'duration': 0.36}], 'summary': 'Improving logging by configuring separate loggers for modules.', 'duration': 42.564, 'max_score': 303.753, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg303753.jpg'}, {'end': 452.74, 'src': 'heatmap', 'start': 425.287, 'weight': 0.706, 'content': [{'end': 428.829, 'text': "If I run this code, then it still doesn't print to the console.", 'start': 425.287, 'duration': 3.542}, {'end': 434.732, 'text': 'It still will create an employee log file and log the messages to that employee log file.', 'start': 428.949, 'duration': 5.783}, {'end': 437.573, 'text': 'Now we can see here that it ran our info logs.', 'start': 435.152, 'duration': 2.421}, {'end': 446.917, 'text': "Now. one thing to notice here is that now it's telling us that we're using this double underscore main logger and not the root logger, like it was before.", 'start': 437.913, 'duration': 9.004}, {'end': 449.719, 'text': 'These log messages are from previous runs.', 'start': 447.518, 'duration': 2.201}, {'end': 452.74, 'text': "Okay, now let's switch back over here to employee real quick.", 'start': 450.259, 'duration': 2.481}], 'summary': 'Code does not print to console, logs to employee log file instead.', 'duration': 27.453, 'max_score': 425.287, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg425287.jpg'}, {'end': 484.904, 'src': 'heatmap', 'start': 450.259, 'weight': 3, 'content': [{'end': 452.74, 'text': "Okay, now let's switch back over here to employee real quick.", 'start': 450.259, 'duration': 2.481}, {'end': 459.524, 'text': "Okay, so we're still configuring this root logger with this file name, log level and format.", 'start': 453.441, 'duration': 6.083}, {'end': 466.207, 'text': "Let's instead configure our specific logger here with those values and leave our root logger alone.", 'start': 459.844, 'duration': 6.363}, {'end': 473.794, 'text': 'So first, to specify the employee log file that we want to log to, we have to add a file handler.', 'start': 466.727, 'duration': 7.067}, {'end': 476.797, 'text': "And to do this, I'll make a new variable.", 'start': 474.214, 'duration': 2.583}, {'end': 479.879, 'text': "And I'm just going to call this file underscore handler.", 'start': 476.877, 'duration': 3.002}, {'end': 484.904, 'text': "And I'm going to set this equal to logging dot file handler.", 'start': 480.38, 'duration': 4.524}], 'summary': 'Configuring specific logger for employee log file with file handler.', 'duration': 34.645, 'max_score': 450.259, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg450259.jpg'}, {'end': 665.873, 'src': 'heatmap', 'start': 617.854, 'weight': 0.826, 'content': [{'end': 620.175, 'text': 'And I can already see I have a typo here.', 'start': 617.854, 'duration': 2.321}, {'end': 621.756, 'text': 'Let me fix that and save it.', 'start': 620.215, 'duration': 1.541}, {'end': 625.318, 'text': 'Okay, so now let me go ahead and rerun our code here.', 'start': 622.376, 'duration': 2.942}, {'end': 627.939, 'text': 'Now it created our employee.log.', 'start': 625.758, 'duration': 2.181}, {'end': 629.3, 'text': "So I'm going to go ahead and open that.", 'start': 627.959, 'duration': 1.341}, {'end': 634.622, 'text': 'And you can see that within here it logged all of the lines that we specified with the correct format.', 'start': 629.8, 'duration': 4.822}, {'end': 641.926, 'text': "So now let's jump back over to our other script where we imported the employee module.", 'start': 635.043, 'duration': 6.883}, {'end': 643.727, 'text': "Let's scroll back up here to the top.", 'start': 642.306, 'duration': 1.421}, {'end': 649.008, 'text': 'Now, remember that before this gave us problems because we were sharing that root logger.', 'start': 644.187, 'duration': 4.821}, {'end': 656.13, 'text': 'But if I rerun this now, then we can see that this time it did create this sample log file.', 'start': 649.349, 'duration': 6.781}, {'end': 662.392, 'text': 'Now, if I open up that sample log, then we can see that we have that different formatting with the time set first.', 'start': 656.471, 'duration': 5.921}, {'end': 665.873, 'text': "So we're logging the time and then the logger.", 'start': 663.012, 'duration': 2.861}], 'summary': 'Code rerun successfully, creating employee.log and sample log file with correct formatting.', 'duration': 48.019, 'max_score': 617.854, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg617854.jpg'}, {'end': 702.73, 'src': 'embed', 'start': 669.014, 'weight': 1, 'content': [{'end': 671.155, 'text': 'And also we are logging out our message.', 'start': 669.014, 'duration': 2.141}, {'end': 675.056, 'text': 'And now let me open up the employee log file.', 'start': 671.755, 'duration': 3.301}, {'end': 678.438, 'text': 'And we can see in here that it logged the values correctly.', 'start': 675.517, 'duration': 2.921}, {'end': 682.44, 'text': 'And it gave the name of employee for the logger this time.', 'start': 678.798, 'duration': 3.642}, {'end': 684.961, 'text': "And that's because this module was imported.", 'start': 682.5, 'duration': 2.461}, {'end': 690.103, 'text': "And if we'd run that directly, then it would be equal to this double underscore main up here.", 'start': 685.321, 'duration': 4.782}, {'end': 694.685, 'text': 'But since we imported that, it got set to employee, which is the name of the module.', 'start': 690.383, 'duration': 4.302}, {'end': 702.73, 'text': "Okay, so, real quick, let's go ahead and set up a logger for this other script that we're currently in,", 'start': 695.245, 'duration': 7.485}], 'summary': 'The employee log file logged values correctly and set the module name to employee.', 'duration': 33.716, 'max_score': 669.014, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg669014.jpg'}, {'end': 840.511, 'src': 'embed', 'start': 810.827, 'weight': 4, 'content': [{'end': 812.528, 'text': "It's nice how this hierarchy works.", 'start': 810.827, 'duration': 1.701}, {'end': 819.916, 'text': "So for example, let's say that we wanted our logger level in this module here set to debug, which it currently already is.", 'start': 812.849, 'duration': 7.067}, {'end': 826.821, 'text': "But now let's say that we only wanted our errors or worse to get logged to the sample log file.", 'start': 820.396, 'duration': 6.425}, {'end': 831.625, 'text': 'Now to do that, we can set levels on the file handlers themselves.', 'start': 827.181, 'duration': 4.444}, {'end': 840.511, 'text': 'So if I wanted to keep my logger level set to debug but wanted to only capture error statements and above in this specific file handler,', 'start': 831.945, 'duration': 8.566}], 'summary': 'Explaining how to set different log levels for file handlers in the module.', 'duration': 29.684, 'max_score': 810.827, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg810827.jpg'}, {'end': 866.802, 'src': 'heatmap', 'start': 840.511, 'weight': 0.707, 'content': [{'end': 848.758, 'text': 'then what I could do is take this file handler here and just say file handler dot set level.', 'start': 840.511, 'duration': 8.247}, {'end': 853.091, 'text': "And I'll set that equal to logging.error.", 'start': 849.989, 'duration': 3.102}, {'end': 858.395, 'text': 'So now if I rerun this code, then it created our log files.', 'start': 853.912, 'duration': 4.483}, {'end': 859.817, 'text': "I'm going to open up our log file.", 'start': 858.435, 'duration': 1.382}, {'end': 862.038, 'text': "And there's nothing in our sample.log.", 'start': 860.137, 'duration': 1.901}, {'end': 866.802, 'text': "We can see that it didn't log those debug statements because the levels didn't match.", 'start': 862.398, 'duration': 4.404}], 'summary': 'Setting log level to error resulted in empty log file.', 'duration': 26.291, 'max_score': 840.511, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg840511.jpg'}], 'start': 303.753, 'title': 'Python logging configuration', 'summary': 'Explains configuring separate loggers for modules and specific loggers in python, emphasizing the creation of new loggers, file handlers, formatting, and log levels for improved logging flexibility and hierarchy.', 'chapters': [{'end': 366.911, 'start': 303.753, 'title': 'Configuring separate loggers for modules', 'summary': 'Discusses the need to configure separate loggers for modules in order to obtain the desired log file, log levels, and formatting, and demonstrates the creation of a new logger for the employee module using the logging.getlogger method and the special double underscore name convention.', 'duration': 63.158, 'highlights': ['The need to configure separate loggers for modules is emphasized to obtain the desired log file, log levels, and formatting.', 'Demonstrates the creation of a new logger for the employee module using the logging.getlogger method and the special double underscore name convention.', 'Emphasizes the use of the special double underscore name convention for naming loggers to ensure proper functionality when executing the code directly or from an import.']}, {'end': 936.724, 'start': 367.331, 'title': 'Python logging: configuring specific loggers', 'summary': 'Explains the process of configuring specific loggers in python, demonstrating the creation of loggers, adding file handlers, setting formatting, and adjusting log levels, resulting in improved logging flexibility and hierarchy.', 'duration': 569.393, 'highlights': ['The process of configuring specific loggers in Python involves creating loggers, adding file handlers, setting formatting, and adjusting log levels for improved logging flexibility and hierarchy. The chapter provides a detailed explanation of configuring specific loggers, including creating loggers, adding file handlers, setting formatting, and adjusting log levels for improved logging flexibility and hierarchy.', "The logger can be used to run log methods, and if the logger doesn't have a specific setting, it will fall back to the root logger. The logger can be used to run log methods, and if the logger doesn't have a specific setting, it will fall back to the root logger, demonstrating the hierarchical nature of loggers.", 'Demonstrates the process of adding a file handler to a specific logger, allowing for more targeted logging to a particular log file. The chapter demonstrates the process of adding a file handler to a specific logger, allowing for more targeted logging to a particular log file, providing a more focused approach to logging.']}], 'duration': 632.971, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg303753.jpg', 'highlights': ['Emphasizes the use of the special double underscore name convention for naming loggers to ensure proper functionality when executing the code directly or from an import.', 'Demonstrates the creation of a new logger for the employee module using the logging.getlogger method and the special double underscore name convention.', 'The need to configure separate loggers for modules is emphasized to obtain the desired log file, log levels, and formatting.', 'Demonstrates the process of adding a file handler to a specific logger, allowing for more targeted logging to a particular log file, providing a more focused approach to logging.', 'The process of configuring specific loggers in Python involves creating loggers, adding file handlers, setting formatting, and adjusting log levels for improved logging flexibility and hierarchy.']}, {'end': 1176.074, 'segs': [{'end': 1021.053, 'src': 'heatmap', 'start': 937.304, 'weight': 0, 'content': [{'end': 942.225, 'text': 'Now it looks like nothing happened, but if I go to our sample.log file here now,', 'start': 937.304, 'duration': 4.921}, {'end': 947.366, 'text': 'we can see that we had a log put in here where it said tried to divide by zero.', 'start': 942.225, 'duration': 5.141}, {'end': 951.687, 'text': "Now, a personal preference of mine is that any time that I'm logging an error,", 'start': 947.846, 'duration': 3.841}, {'end': 957.028, 'text': 'I usually like to include the trace back so that I can get more information about what exactly happened.', 'start': 951.687, 'duration': 5.341}, {'end': 960.329, 'text': 'And the logging module allows us to do this very easily.', 'start': 957.388, 'duration': 2.941}, {'end': 967.591, 'text': 'We can just do that by changing this logging.error Instead, make that logging.exception.', 'start': 961.169, 'duration': 6.422}, {'end': 972.993, 'text': 'So now let me rerun that code again and switch back to our sample log file.', 'start': 967.931, 'duration': 5.062}, {'end': 976.134, 'text': 'And you can see that now included in our log.', 'start': 973.353, 'duration': 2.781}, {'end': 977.234, 'text': 'we got that.', 'start': 976.134, 'duration': 1.1}, {'end': 981.716, 'text': 'we tried to divide by zero, but it also included the trace back here with some more information.', 'start': 977.234, 'duration': 4.482}, {'end': 985.862, 'text': 'Okay, so let me go back to our script here.', 'start': 982.421, 'duration': 3.441}, {'end': 993.645, 'text': "So another good thing about this being modularized is that it's easy to add multiple handlers to a logger.", 'start': 986.802, 'duration': 6.843}, {'end': 1000.627, 'text': "So for example, let's say that we did want to see these debug statements that we're executing down here at the bottom.", 'start': 994.005, 'duration': 6.622}, {'end': 1003.588, 'text': 'but we only wanted to display those to the console.', 'start': 1001.147, 'duration': 2.441}, {'end': 1013.211, 'text': "So what we could do here is create another handler, but instead of a file handler, what we're gonna do is create a stream handler.", 'start': 1004.268, 'duration': 8.943}, {'end': 1014.911, 'text': 'So let me show you how this works here.', 'start': 1013.651, 'duration': 1.26}, {'end': 1021.053, 'text': "So we can just come down here and create another handler, and we'll call this stream underscore handler.", 'start': 1014.951, 'duration': 6.102}], 'summary': 'Logging errors with tracebacks and adding multiple handlers for different outputs.', 'duration': 44.412, 'max_score': 937.304, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg937304.jpg'}, {'end': 1076.54, 'src': 'embed', 'start': 1050.883, 'weight': 2, 'content': [{'end': 1056.205, 'text': 'Now you can see that we have both the file handler and the stream handler added to this single logger.', 'start': 1050.883, 'duration': 5.322}, {'end': 1063.087, 'text': 'So now if I run this code, then you can see that it logged our debug statements in the console.', 'start': 1056.665, 'duration': 6.422}, {'end': 1069.713, 'text': 'And also these errors show up here too, but those are also getting sent specifically to the log file with the error logs.', 'start': 1064.048, 'duration': 5.665}, {'end': 1076.54, 'text': "Now, one thing to notice here is that the formatting to the console isn't the same that we had in our file,", 'start': 1070.134, 'duration': 6.406}], 'summary': 'Both file handler and stream handler added to logger, logging debug statements in console and errors in log file.', 'duration': 25.657, 'max_score': 1050.883, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg1050883.jpg'}, {'end': 1148.991, 'src': 'embed', 'start': 1110.455, 'weight': 3, 'content': [{'end': 1114.838, 'text': 'Hopefully after these videos, you have a good idea for how you can begin to add logging to your projects.', 'start': 1110.455, 'duration': 4.383}, {'end': 1119.441, 'text': 'This is something that almost every project needs in production at some point.', 'start': 1115.398, 'duration': 4.043}, {'end': 1123.844, 'text': 'And good logs can save you a lot of headaches when trying to debug problems.', 'start': 1120.081, 'duration': 3.763}, {'end': 1124.564, 'text': 'You know.', 'start': 1124.324, 'duration': 0.24}, {'end': 1127.765, 'text': 'if you are interested in going even more advanced than this,', 'start': 1124.564, 'duration': 3.201}, {'end': 1133.667, 'text': 'then I would suggest getting on the Python documentation and looking up all the different handlers that they have,', 'start': 1127.765, 'duration': 5.902}, {'end': 1136.607, 'text': 'because you know you can set it up to where.', 'start': 1133.667, 'duration': 2.94}, {'end': 1141.689, 'text': 'if you get an error, then it sends you an email or gets added to a queue or something like that.', 'start': 1136.607, 'duration': 5.082}, {'end': 1146.13, 'text': "They also have rotating logs so that one log file doesn't build up too much.", 'start': 1142.229, 'duration': 3.901}, {'end': 1148.991, 'text': 'All kinds of functionality built in here to the log module.', 'start': 1146.49, 'duration': 2.501}], 'summary': 'Logging is essential for projects; advanced features available in python documentation can automate error handling and offer different log handling options.', 'duration': 38.536, 'max_score': 1110.455, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg1110455.jpg'}], 'start': 937.304, 'title': 'Logging errors and multiple handlers', 'summary': 'Explains logging errors and including tracebacks using the logging module, resulting in a more informative log file, and demonstrates adding multiple handlers to a logger to display debug statements on the console alongside a file handler, suggesting further exploration of advanced logging functionalities in python.', 'chapters': [{'end': 981.716, 'start': 937.304, 'title': 'Logging errors and including tracebacks', 'summary': 'Explains the process of logging errors and including tracebacks using the logging module, demonstrating how to log an error and include a traceback, resulting in a more informative log file.', 'duration': 44.412, 'highlights': ['By changing logging.error to logging.exception, the log file now includes the traceback, providing more information about the error.', 'Logging errors with tracebacks can enhance the log file and provide more detailed information about the occurrences.']}, {'end': 1176.074, 'start': 982.421, 'title': 'Logging with multiple handlers', 'summary': 'Explains how to add multiple handlers to a logger, demonstrating the addition of a stream handler to display debug statements on the console alongside a file handler, emphasizing the importance of logging in projects and suggesting further exploration of advanced logging functionalities in python.', 'duration': 193.653, 'highlights': ['The chapter demonstrates adding a stream handler alongside a file handler to the logger, enabling the display of debug statements on the console and error logs in a file, showcasing the versatility of multiple handlers in logging. demonstrates adding a stream handler, showcasing the versatility of multiple handlers', 'The chapter emphasizes the importance of logging in projects, highlighting how good logs can save a lot of headaches when debugging problems, indicating its significance in production environments. emphasizes the importance of logging in projects, indicating its significance in production environments', 'The chapter suggests further exploration of advanced logging functionalities in Python, including different handlers for specific actions like sending emails on errors and using rotating logs to prevent log file buildup, encouraging viewers to delve into the Python documentation for more comprehensive understanding. suggests further exploration of advanced logging functionalities in Python']}], 'duration': 238.77, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/jxmzY9soFXg/pics/jxmzY9soFXg937304.jpg', 'highlights': ['By changing logging.error to logging.exception, the log file now includes the traceback, providing more information about the error.', 'Logging errors with tracebacks can enhance the log file and provide more detailed information about the occurrences.', 'The chapter demonstrates adding a stream handler alongside a file handler to the logger, enabling the display of debug statements on the console and error logs in a file, showcasing the versatility of multiple handlers in logging.', 'The chapter emphasizes the importance of logging in projects, highlighting how good logs can save a lot of headaches when debugging problems, indicating its significance in production environments.', 'The chapter suggests further exploration of advanced logging functionalities in Python, including different handlers for specific actions like sending emails on errors and using rotating logs to prevent log file buildup, encouraging viewers to delve into the Python documentation for more comprehensive understanding.']}], 'highlights': ['Covers loggers, handlers, and basic configurations in Python logging.', 'Demonstrates the usage of log files, log levels, and custom formatting in Python logging.', 'Explains the significance of the root logger when working with smaller applications and specific files.', 'Configuring separate loggers is crucial to avoid conflicting configurations and incomplete logging.', 'Changing log statements to info level allows them to log the information, highlighting the impact of logger configuration on the logging output.', 'Emphasizes the use of the special double underscore name convention for naming loggers to ensure proper functionality when executing the code directly or from an import.', 'Demonstrates the creation of a new logger for the employee module using the logging.getlogger method and the special double underscore name convention.', 'The need to configure separate loggers for modules is emphasized to obtain the desired log file, log levels, and formatting.', 'Demonstrates the process of adding a file handler to a specific logger, allowing for more targeted logging to a particular log file, providing a more focused approach to logging.', 'The process of configuring specific loggers in Python involves creating loggers, adding file handlers, setting formatting, and adjusting log levels for improved logging flexibility and hierarchy.', 'By changing logging.error to logging.exception, the log file now includes the traceback, providing more information about the error.', 'Logging errors with tracebacks can enhance the log file and provide more detailed information about the occurrences.', 'The chapter demonstrates adding a stream handler alongside a file handler to the logger, enabling the display of debug statements on the console and error logs in a file, showcasing the versatility of multiple handlers in logging.', 'The chapter emphasizes the importance of logging in projects, highlighting how good logs can save a lot of headaches when debugging problems, indicating its significance in production environments.', 'The chapter suggests further exploration of advanced logging functionalities in Python, including different handlers for specific actions like sending emails on errors and using rotating logs to prevent log file buildup, encouraging viewers to delve into the Python documentation for more comprehensive understanding.']}