Formatting the Output
While you can pass any variable that can be represented as a string from your program as a message to your logs, there are some basic elements that are already a part of the
LogRecord and can be easily added to the output format. If you want to log the process ID along with the level and message, you can do something like this:
import logging logging.basicConfig(format='%(process)d-%(levelname)s-%(message)s') logging.warning('This is a Warning')
Here’s what you’ll get:
18472-WARNING-This is a Warning
Become a Member to join the conversation.