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.
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.
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".
Here what I would do if I was starting now! First of all, learn the dependencies like algorithms and programming logic; Second step would be learn the basics from python: variables, typing, functions creation Third step learn how to use libs Fourth understand object orientation and how to implement in python From here you can select one of the many existent paths for python programmers like Data or Software engineering, development or architechture, python is more a backend language so you can choose if you going for an API path and learn FastAPI, Flask, Django... Many other possible paths from here, i think here is the time you need to stop again and think, ok, right now, where do I go
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?
It looks like it's been a year and no one answered your question so I'll try. When you import modules (built in and custom) it will run the code in those modules automatically. Using the example in the video if he imported logging first, added the code for basicConfig after the import, then imported the other modules then the logging will be consistent. If he did all his imports first then set up basicConfig then the logging wouldn't work as expected. It's more complicated so I'm simplifying it. I recommend that you have a .py file that does the logging setup so it sets up the root logger using basicConfig, import that file first before any other modules, then import the other modules so the root logger is already configured.
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.
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
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
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.
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:
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 😀
im getting all sorts of errors just initializing the first line logging.basicConfig...etc... aaanyways.. I will look into this later when I need it more
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!
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.
What's been missing in my Python journey is this video. Thank you!
It will be great if you add real-world examples in your videos.
It helps to understand where these modules are used
Huh. I've been writing my own logging functions. This might come in handy in the next project. Thanks!
Super helpful video! Thanks very much!
Well done, to the point, clear, will look for your other videos.
I love your tutorials. Very well explained. Thanks!
Thank you!
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.
exactly what I need right now, thanks!
exactly the tutorial I needed, I heard about logging few days ago and was planning to check it out
Excellent teaching. Thanks!
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.
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.
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
for me it is: "I want to make a bot / program that does X". Then I start step by step looking at instructions online on how to achieve each step.
Here what I would do if I was starting now!
First of all, learn the dependencies like algorithms and programming logic;
Second step would be learn the basics from python: variables, typing, functions creation
Third step learn how to use libs
Fourth understand object orientation and how to implement in python
From here you can select one of the many existent paths for python programmers like Data or Software engineering, development or architechture, python is more a backend language so you can choose if you going for an API path and learn FastAPI, Flask, Django...
Many other possible paths from here, i think here is the time you need to stop again and think, ok, right now, where do I go
Code every day.
Start with small projects
Thank you for this very useful video!
Thank you 🥺🥰💕
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?
It looks like it's been a year and no one answered your question so I'll try.
When you import modules (built in and custom) it will run the code in those modules automatically. Using the example in the video if he imported logging first, added the code for basicConfig after the import, then imported the other modules then the logging will be consistent. If he did all his imports first then set up basicConfig then the logging wouldn't work as expected. It's more complicated so I'm simplifying it.
I recommend that you have a .py file that does the logging setup so it sets up the root logger using basicConfig, import that file first before any other modules, then import the other modules so the root logger is already configured.
Is it possible to raise an error automatically with the logging.error and logging.critical call?
perfect content
I need more of your videos
Thank you very much bro !!!
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.
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
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
I wonder how many of us watch both your and Mcoding's videos
can you point different log levels to different files?
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.
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:
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 😀
which ide you are using
Is there an option for global configuration?
im getting all sorts of errors just initializing the first line logging.basicConfig...etc... aaanyways.. I will look into this later when I need it more
Please Please Pretty Please keep making videos like this. The world needs it. YOU ARE A PERSONAL HERO. 🤗
Nice video, but why would anyone use such an archaic datetime format in a log file? Just stick to the default
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
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