"Stop Printing, Start Logging!" (Logging Tutorial For Python Developers)
Вставка
- Опубліковано 8 лип 2024
- Logging is far more powerful than printing in Python. It really gives you a lot of free information, so in this video I will teach you the basics of how you can get started with using the logging module in Python, so that you can create far more detailed logs!
Logrecord Attributes:
docs.python.org/3/library/log...
▶ Become job-ready with Python:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels
00:00 Intro
00:24 import logging
00:34 What is logging?
00:46 Logging levels
03:39 Log file
04:20 Adding variables
05:50 Creating detailed logs
06:43 Formatting
12:40 Conclusion
A tutorial no one asked for but everyone needed
i agree
No other way to put it
For the young developers: the creation of a log file is vital in production to quickly detect/follow any failure!
It will be great if you add real-world examples in your videos.
It helps to understand where these modules are used
Thank you for this video.
There is another reason why you should use the "old" method of string formatting instead of f-strings:
The message string is only expanded/formatted if it is printed/logged - so it will save some procesing power, especially for debug messages which a rarely enabled.
If you use a f-string it will be formatted before it is handed over to the logger - regardles if it is used or not.
exactly the tutorial I needed, I heard about logging few days ago and was planning to check it out
Huh. I've been writing my own logging functions. This might come in handy in the next project. Thanks!
Tankyou for the video. It's another very informative and important subject. I have created a user snippet for logging and using it all the time.
Well done, to the point, clear, will look for your other videos.
What is the fastest way to learn Python?
For me it was learning through books that have interactive content. That way you practice while you learn is easier to remember what you just learned. I learned with:
"Programming Not Painfully Boring" for the basics of programming and "Smarter Way to Learn Python".
coding
I love your tutorials. Very well explained. Thanks!
Thank you!
exactly what I need right now, thanks!
Excellent teaching. Thanks!
Thank you for this very useful video!
Thank you soooooooooo much, it worked all perfectly in the project at work, where we have build an AI chatbot for space sector training solutions.
Thank you very much bro !!!
Thank you 🥺🥰💕
perfect content
I need more of your videos
Nice start. Could use a better, real world example. Like combining it with a normal exception you run into and how to log that. Or maybe with a debug example where you try to follow a variable? Is that an example you would use it for in the real world? Im a beginner.. I usually struggle with youtube tutorials because they lack real world examples.
Yeah I was gonna say the same. Need to see this properly in action to understand why it’s useful. Seems just like print with extra steps at the moment.
This was really an awesome share for debugging.
I recently found pdb.
import pdb
Can't recall how to istantiate it but you may get something out of it.
You can put break points and a host of things from the command line.
The 2 of these tools together would be a great thing to have in the tool box for complex applications.
I really like the logging of imported modules.
Breadcrumb Vacuum Cleaner
Kudos
AFAIR a classic string formatting ala `log.error("Cant find file %s", filename)` is preferred, so tools and services like Sentry can properly group messages.
Great, already known, that logging lib is there, but this made it more clear. I just wonder if it possible to change config for the level during the code is excuted (e.g. use debug for some new code) while keeping warning for the rest. further, I figured out, that style="{" in the basicconfig enables better formatting like this {asctime:
12:30 If you import hello_module before basicConfig, then the configurations passed to basicConfig won't be applied? Does that mean import logging and basicConfig needs be the first and second line in your program everytime?
Problem I have is how to handle the log output. either it's too detailed or not enough, or I need different level of detail in different parts of the code etc... ist there a good viewer for the logfile that would maybe thread the output, allowing to collapse/expand the threaded messages. integration in visual studio would be a plus 😀
Is it possible to raise an error automatically with the logging.error and logging.critical call?
Are there even people running Python versions pre 3.6, where you don't have f-strings, or even worse, 2.7 where don't have the format() method? A more pertinent question still, why would even be concerned about this kind of backwards compatibility?
Really cool video though. Would've been cool to see real case use though
which ide you are using
Please Please Pretty Please keep making videos like this. The world needs it. YOU ARE A PERSONAL HERO. 🤗
Have doubt:
1. logging.basicConfig can create fille hanlder? .
2. Have created two logging object using logging.basicConfig
Is it possible to copy log content from log 1 to log 2. While copy I don't want to copy the timestamp, thread details from log1, need to copy only the content.
can you point different log levels to different files?
Is there an option for global configuration?
I wonder how many of us watch both your and Mcoding's videos
I think this lib need then you are finish app, and you need ,ake some login temp files, but in dev process print(1) is a GOD XD
Nice video, but why would anyone use such an archaic datetime format in a log file? Just stick to the default
Which ide is this
Vs Code
Indently says its PyCharm in the video.
@@adityasinha7664 Nope, it's PyCharm. He's using the new UI (beta)
loguru > built-in logging