Python Tutorial: Logging Basics – Logging to Files, Setting Levels, and Formatting

///Python Tutorial: Logging Basics – Logging to Files, Setting Levels, and Formatting

Python Tutorial: Logging Basics – Logging to Files, Setting Levels, and Formatting

FavoriteLoadingAdd to favorites

In this Python Tutorial, we will be going over the basics of logging. We will learn how to switch out our print statements for logs, change the logging level, add logs to files, and also how to change the format of those logs. Let’s get started.

Advanced Logging Video –
Log Record Attribute Docs:

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

source

By |2019-10-02T23:08:18+00:00October 2nd, 2019|Python Video Tutorials|32 Comments

32 Comments

  1. viknesh s.k October 2, 2019 at 11:08 pm - Reply

    That's really a great tutorial.. One issue i had was, log files are not getting generated. any reason for it???

  2. bb bb October 2, 2019 at 11:08 pm - Reply

    Larger font please

  3. Jeff Rowe October 2, 2019 at 11:08 pm - Reply

    At 4:12, you changed 4 print statements to logging.debug. How do you edit all four statements at once?

  4. Ashish Srivastava October 2, 2019 at 11:08 pm - Reply

    Great video .. how did he select multiple in vs code( guess) and edit code at multiple place at once ?

  5. Hossen Murad Rakib October 2, 2019 at 11:08 pm - Reply

    Hello sir!!! I'm waiting for ur tkinter videos!!

  6. Jx Wan October 2, 2019 at 11:08 pm - Reply

    Hi Corey, can you please advise on how can i retrieve the data based on the latest date & time in the log file and the code to replace the data with another at any given time?? Urgent help please

  7. rubebop October 2, 2019 at 11:08 pm - Reply

    Absolutely great. Thank you so much.

  8. Albert Soo Hong Wei October 2, 2019 at 11:08 pm - Reply

    You are my Rich Dad, Thank you Corey !

  9. Rajveer Singh October 2, 2019 at 11:08 pm - Reply

    Sir, I am a beginner, How can I set the Project level variables. So That I can access them anywhere in any .py file.

  10. Petrockspiracy October 2, 2019 at 11:08 pm - Reply

    I literally copied the code and get this error:
    AttributeError: module 'logging' has no attribute 'debug'

    So I found the solution: don't name your file logging.py :p

  11. Deepankesh Ranjan October 2, 2019 at 11:08 pm - Reply

    Good work. Something which people are interested and useful

  12. MrBamshy October 2, 2019 at 11:08 pm - Reply

    I think following this great lesson step by step using the python interpreter directly requires reloading the logging module – importlib.reload(logging). Thanks Corey! You remain my favorite!!

  13. Jen Manzella October 2, 2019 at 11:08 pm - Reply

    Your tutorials are awesome! Do you offer mentorship?

  14. TechNick October 2, 2019 at 11:08 pm - Reply

    Hey Corey which text editor do you use?

  15. Ruchila Sawant October 2, 2019 at 11:08 pm - Reply

    Your video is very nice.But I want to ask you about formatting logs.I have open log file in pycharm.I can see it,spliit it and now all logs are in list format.so there are hundreds of lists.How can now apply for loop for finding an item in list and use loops for different operations.Please reply back.

  16. Kerwin So October 2, 2019 at 11:08 pm - Reply

    Other tutorials made me scared of Python logging, I didn't realize it could be this simple.
    Being a good coder and being a good teacher are 2 different things. You sir are both. Thank you and God bless.

  17. fadop3zzz October 2, 2019 at 11:08 pm - Reply

    what text editor is he using?

  18. Filip Špila October 2, 2019 at 11:08 pm - Reply

    Thanks that you exist!

  19. Christian Suytings October 2, 2019 at 11:08 pm - Reply

    which IDE (for Linux) do you use?

  20. Daniel Lavedonio de Lima October 2, 2019 at 11:08 pm - Reply

    Is it possible to log to a file and print on console at the same time?

  21. Chromazmoves October 2, 2019 at 11:08 pm - Reply

    when watch a coding video get a paper and a nice donut

  22. praveenraj sr October 2, 2019 at 11:08 pm - Reply

    Thank you very much! This is awesome video 🙂 helped me a lot.

  23. adnan Hashem October 2, 2019 at 11:08 pm - Reply

    hi i want your help in Price monitoring from sites (monitor prices for 100 products from site)

  24. Fat Letterman October 2, 2019 at 11:08 pm - Reply

    Well I’m pretty earlier but thanks for this tutorial

  25. Vivek Reshi October 2, 2019 at 11:08 pm - Reply

    What a video. Thanks!

  26. Mike Reyes October 2, 2019 at 11:08 pm - Reply

    This is my first time ever trying to learn software development. I've been watching your videos for a week now and I've learned more than the python book I bought. I do have a question though. In a real life scenario I don't think you want the user adding the names in the body of your program. Do you have a video of how to ask the user to input employee names outside of the program or example and logs it?

    Reply

  27. MOhan Talupula October 2, 2019 at 11:08 pm - Reply

    Great..!!
    Thanks a lot man..

  28. Eduardo Lucas October 2, 2019 at 11:08 pm - Reply

    That was simply brilliant!

  29. K W October 2, 2019 at 11:08 pm - Reply

    Sorry 1 more quick question.
    The logging files look as though they could fill up fast is there a way to only hold the records in the file for a certain amount of time?

  30. K W October 2, 2019 at 11:08 pm - Reply

    Just curious since we use the dot notation with the logging.debug does that mean we are calling it from a class within the package?

  31. Alex October 2, 2019 at 11:08 pm - Reply

    The log file isn't being created – is there any reason this might be the case?

  32. kj October 2, 2019 at 11:08 pm - Reply

    What IDE is that?

Leave A Comment

*