Python Logging - Tutorial

preview_player
Показать описание
I'm sure many of you are guilty of using the standard print debugging method, and you just have a bunch of print statements scattered all over the place. There is nothing inherently wrong with doing that, and in smaller programs it's completely fine, but once you get into larger programs you'll definitely want to have a persistent log. Watch the video to learn more!

📄 Resources 📄

⭐️ Timestamps ⭐️
00:00 | Why Use Logging?
01:03 | ProgrammingExpert
01:32 | Logging Levels
04:09 | Logging To A File
07:32 | Logging Variable Values
08:45 | Logging Exceptions
10:16 | Custom Loggers
12:21 | Handles and Formatters
14:19 | Conclusion

◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️

◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️

⭐️ Tags ⭐️
- Tech With Tim
- Logging
- Code Log
- Why Use Logging
- What is Logging

⭐️ Hashtags ⭐️
#TechWithTim #Logging #Programming
Рекомендации по теме
Комментарии
Автор

Finally...Someone gives an informative lecture/demo on Python's logging engine. This was excellent and would have saved me a bit of time and confusion a couple of years ago. I use a separate "logger" for each module for large apps. This way I know what module (and in many cases the class and/or function) that generated the message. The only problem with this type of logging is that the module level logger (by definition) is a "global" variable. Recently I implemented a color-coded console-only logger also. Once you understand the various "logging" components (handler, formatter, name) it's really not that hard to do. Excellent Video !

johnnytoobad
Автор

I was *literally* just searching about logging in python for a project yesterday... just in time Tim 👍

danub
Автор

OK, now I understand why you have 1.1M subscribers: exceptional content delivered exceptionally well. First time seeing your content, instant subscriber. Keep up the good work.

mccdan
Автор

I haven't really bridged the gap into intermediate level projects yet. I've used logging a couple of times before, but I can def see how it would be more useful in larger, more mature, programs. Thanks for the video!

BrandonJacobson
Автор

Loguru is my go-to logging module, makes it easy to define custom levels, multiple logging sinks, and i just parse the data into a logging SQL Server table and it is GLORIOUS

BryanJenks
Автор

By the way, log.log is unchanged not because you are not using it but because you overwrite it with the same log text. All log comes from a logger eventually goes to its parent logger (in this case: root logger).And if you don’t want this behavior, you need to set logger.propagate = False.

johnnyz
Автор

Amazing video! I'd like to add, however, that most linters recommend using the 'args' of the logging levels to embed variables. For example:

logging.info(f"the value of x is {x}") -> wrong
logging.info("the value of x is %d" % x) -> wrong
logging.info("the value of x is %d", x) -> correct approach

Do note that all three ways shown above do work - it's just that the third method is recommended for use.

krishnans
Автор

Listen i won't say that i intended to use print as my main debugging tool but it just naturally happened because i didn't realize that debugging already did most of the work for you, heck at first i didn't even really know what debugging was.

Great tutorial however I'll end up using it quite a bit in the long term and it saves me some work so nice.

ABEL-cdsp
Автор

Dont use f-string when logging. Because, if you use logger.debug("text %s", variable), the text formating will only happen, if the debug level is active. If you use f-string, the string will be formated, even before it is decided wether the msg will be logged, thus losing performance

jurajlk
Автор

no joke, i was just looking for a logging in python video. thanks a lot Tim ❤️

moondevonyt
Автор

thanks for this, you have explained logging in a really simple and straightforward manner. You have probably saved me a lot of effort in trawling through documentation. Much appreciated

davecapstick
Автор

lol, reading all the comments about people searching for logging and praising your video, like it came out the same day they commented.. then i realized the video came out 24 hrs ago, and i too searched for logging the same day the video came out xD

enzanto
Автор

short & crisp explanation. Perfect!

deveshgolwalkar
Автор

best thing that i found today about logging-python

hemashankartalupuri
Автор

I've been following you since under 100k subscribers... somehow you consistently produce content that aligns with what I am in the process of learning. Thank you! (I'm a former gryphon too!)

ifthennotagain
Автор

i have been debugging all day with those print's. thanks for another way

mikez
Автор

Cheers Tim! Another Python skill in the bag!

ayupitsali
Автор

Nice.We would glad to see about Golang (logging, unit testing and other advanced topics )

khazartalibov
Автор

Amazing channel. Has helped me so much when studying to become a software developer. Amazing work really!

EarnestG
Автор

Everything i needed in just 15 Minutes! Perfect

ParaSteve