Logging - Intermediate Python Programming p.22

preview_player
Показать описание
Welcome to part 22 of the intermediate Python programming tutorial series. We're going to be covering logging in Python .

The idea of Python's logging module is to make your life easier. Have you ever maybe added print functions/statements in your code at various places to note where your code is and what's running? Then maybe commented it out? Maybe you got fancy and created a constant like debug = True, then had some lines like if debug: print(something). If this sounds like you, or if it sounds like something that you might find useful, chances are, you should be using logging instead. Maybe you haven't yet needed to do such things, but, eventually you may find yourself in a situation where you do want to temporarily track what your code is doing, but not always. Using print can help in a pinch, but your life will be easier in the long run if you bake logging into your code early on. With logging, you can both output to console as well as saving to a file, all depending on varying debugging levels you can choose from.

Рекомендации по теме
Комментарии
Автор

It's always funny when Harrison made some mistake with brackets and you already found it and trying to help him, speaking with your monitor like: Here! Here! :D

upyqptv
Автор

just for general knowledge, on about 4:20, you said that if you can get big log files and have storage space problems since the log files are so big, a good way to handle this is importing "from logging.handlers import RotatingFileHandler" it handles that problem by configuring a max file size, and number of files, when the log file reaches that size it will close it and create a new file, when the number of files reaches the number of files you configured, it will delete the oldest one.
a great little handler that will help alot

nizanu
Автор

Fun fact -
The terms "bug" and "debugging" are popularly attributed to Admiral Grace Hopper in the 1940s. While she was working on a Mark II Computer at Harvard University, her associates discovered a moth stuck in a relay and thereby impeding operation, whereupon she remarked that they were "debugging" the system.


Great videos man, keep it up :)

steinarrhrafnhoskuldsson
Автор

Before knowing about logging I created my own small logging module that logs the time, module name, and the message I wish to log - formatted nicely. It'll generate a new log file every 24 hours.

Not really practical, but it sure helped me out a lot, especially because I was too lazy to read the documentation for standard logging.

Thanks for the video!

idle_user
Автор

series is going awesome, looking forward to more videos on Python :)

sanjayshr
Автор

The reason your SQL logs keep growing is probably that some transactions are left open. Creating a scheduled procedure to kill the hanging transactions should help.

sinngleton
Автор

Thank you very much, you helped me a lot!
Also I had to giggle about 'Blobject' ;)

QuiGonTobi
Автор

There's no need to call the str method on arguments passed to format. The format method handles that for you by default (can be overidden).

Codiferus
Автор

Nice, thx ! Your tutorials are awsome !

nictuniema
Автор

One of the best tutorials I've seen so far! Excellent work

m_nabr
Автор

thank you for this series by the way, i've been too used to the functional paradigm while using python, and while i've started using classes, it's v. v. nice to see these intermediate techniques.

question: when would you use multiple .py files and start using imports? i see a lot of java programs implement a ton of classes, and i'm wondering why most python programs don't do the same thing.

CakeBossan
Автор

Would be nice to use it in the next big project you show us. Because I would not know when to use it. And I don't see much difference to print statements. Like in reinforced learning.

knabbagluon
Автор

Creates a log file to find what the problem is. The log file becomes the problem... #logception

VascoCC
Автор

On the website, on the page it shows part 1 instead of part 22

sportacus
Автор

is it a good idea to create multiple log files using the datetime library and adding it onto the filename suffix?

revdevstudios
Автор

Nice vid ! Is there a way to make the program open the file were the log were put at the end ? So if there is an error it pops on your screen

Bouex
Автор

There is also an 'error' level between 'critical' and 'warning'.

sntshkmr
Автор

is there a way to have the logging on another thread so it wont interfere the program and what can you do with multithreaded programs writing to a single file? can it cause problems?

nizanu
Автор

My log files do not close properly. should I use a .close() on the flog file. Should this be used with the context manager "With"

alexandarjelenic