Logging Variable Data
In most cases, you would want to include dynamic information from your application in the logs. You have seen that the logging methods take a string as an argument, and it might seem natural to format a string with variable data in a separate line and pass it to the log method. But this can actually be done directly by using a format string for the message and appending the variable data as arguments. Here’s an example:
import logging name = 'John' logging.error('%s raised an error', name)
Here’s what you’ll get:
ERROR:root:John raised an error
Comments & Discussion
Become a Member to join the conversation.