3.1 Custom Levels 4 Useful Handlers 14 Logged messages are formatted for presentation through instances of the Formatter class. They are initialized with a format string suitable for use with the % operator and a dictionary. The$_{NullHandler}$ ,$_{StreamHandler}$and$_{FileHandler}$ classes are defined in the core logging package. The other handlers are defined in a sub-module,$_{logging.handlers}$ . (There is also another sub-module,$_{logging.}$ $_{config}$, for configuration functionality.) New in version 3.2: The$_{QueueHandler}$class. New in version 3.1: The$_{NullHandler}$class. Defining your own levels is possible, but should not be necessary, as the existing levels have been chosen on the basis of practical experience. However, if you are convinced that you need custom levels, great care should be exercised when doing this, and it is possibly a very bad idea to define custom levels if you are developing a library . That’s because if multiple library authors all define their own custom levels, there is a chance that the logging output from such multiple libraries used together will be difficult for the using developer to control and/or interpret, because a given numeric value might mean different things for different libraries. In addition to the base Handler class, many useful subclasses are provided: 1. StreamHandler instances send messages to streams (file-like objects). 2. FileHandler instances send messages to disk files. 3. $_{BaseRotatingHandler}$is the base class for handlers that rotate log files at a certain point. It is not meant to be instantiated directly. Instead, use RotatingFileHandler or TimedRotatingFileHandler . 4. RotatingFileHandler instances send messages to disk files, with support for maximum log file sizes and log file rotation. 5. TimedRotatingFileHandler instances send messages to disk files, rotating the log file at certain timed intervals. 6. $_{SocketHandler}$instances send messages to TCP/IP sockets. Since 3.4, Unix domain sockets are also supported. 7. DatagramHandler instances send messages to UDP sockets. Since 3.4, Unix domain sockets are also supported. 8. SMTPHandler instances send messages to a designated email address. 9. SysLogHandler instances send messages to a Unix syslog daemon, possibly on a remote machine. 10. $_{NTEventLogHandler}$instances send messages to a Windows NT/2000/XP event log. 11. MemoryHandler instances send messages to a buffer in memory, which is flushed whenever specific criteria are met. 12. HTTPHandler instances send messages to an HTTP server using either$_{GET}$ or$_{POST}$ semantics. 13. WatchedFileHandler instances watch the file they are logging to. If the file changes, it is closed and reopened using the file name. This handler is only useful on Unix-like systems; Windows does not support the underlying mechanism used. 14. QueueHandler instances send messages to a queue, such as those implemented in the $_{queue}$or multiprocessing modules. 15. $_{NullHandler}$instances do nothing with error messages. They are used by library developers who want to use logging, but want to avoid the ‘No handlers could be found for logger XXX’ message which can be displayed if the library user has not configured logging. See Configuring Logging for a Library for more information.