Useful Handlers
In addition to the base Handler Class, many useful subclasses are provided.
Handler |
Description |
---|---|
StreamHandler | Sends messages to streams (file-like objects). |
FileHandler | Sends messages to disk files. |
BaseRotatingHandler | Base class for handlers that rotate log files at a certain point. Use RotatingFileHandler or TimedRotatingFileHandler instead. |
RotatingFileHandler | Sends messages to disk files, with support for maximum log file sizes and log file rotation. |
TimedRotatingFileHandler | Sends messages to disk files, rotating the log file at certain timed intervals. |
SocketHandler | Sends messages to TCP/IP sockets. Also supports Unix domain sockets since Python 3.4. |
DatagramHandler | Sends messages to UDP sockets. Also supports Unix domain sockets since Python 3.4. |
SMTPHandler | Sends messages to a designated email address. |
SysLogHandler | Sends messages to a Unix Syslogthe daemon, possibly on a remote machine. |
NTEventLogHandler | Sends messages to a Windows NT/2000/XP event log. |
MemoryHandler | Sends messages to a buffer in memory, which is flushed whenever specific criteria are met. |
HTTPHandler | Sends messages to an HTTP server using either GET or POST semantics. |
WatchedFileHandler | Watches the file it is logging to. If the file changes, it is closed and reopened using the file name. |
QueueHandler | Sends messages to a queue, such as those implemented in the queue or multiprocessing modules. |
NullHandler | Does nothing with error messages. Used by library developers to avoid ‘No handlers could be found for logger’ message. |
Logging in Python
Logging is a means of tracking events that happen when some software runs. Logging is important for software developing, debugging, and running. If you don’t have any logging record and your program crashes, there are very few chances that you detect the cause of the problem. And if you detect the cause, it will consume a lot of time. With logging, you can leave a trail of breadcrumbs so that if something goes wrong, we can determine the cause of the problem.
There are a number of situations like if you are expecting an integer, you have been given a float and you can a cloud API, the service is down for maintenance, and much more. Such problems are out of control and are hard to determine.