1.5 Logging variable data 5 which would display something like this: import logging logging.basicConfig(format=' %(asctime)s %(message)s ', datefmt ='%m/ %d /%Y %I:%M:%S %p ↪ → ') logging.warning( 'is when this event was logged. ') import logging logging.basicConfig(format=' %(asctime)s %(message)s ') logging.warning( 'is when this event was logged. ') DEBUG:This message should appear on the console INFO:So should this WARNING:And this, too import logging logging.basicConfig(format=' %(levelname)s : %(message)s ', level =logging.DEBUG) logging.debug( 'This message should appear on the console') logging.info('So should this ') logging.warning( 'And this, too') To log variable data, use a format string for the event description message and append the variable data as arguments. For example: import logging logging.warning( ' %s before you %s ','Look ','leap! ') will display: WARNING:root:Look before you leap! As you can see, merging of variable data into the event description message uses the old, %-style of string for- matting. This is for backwards compatibility: the logging package pre-dates newer formatting options such as$_{str.}$ format() and string.Template . These newer formatting options are supported, but exploring them is outside the scope of this tutorial: see formatting-styles for more information. To change the format which is used to display messages, you need to specify the format you want to use: which would print: Notice that the ‘root’ which appeared in earlier examples has disappeared. For a full set of things that can appear in format strings, you can refer to the documentation for logrecord-attributes, but for simple usage, you just need the levelname (severity), message (event description, including variable data) and perhaps to display when the event occurred. This is described in the next section. To display the date and time of an event, you would place ‘%(asctime)s’ in your format string: which should print something like this: 2010-12-12 11:41:42,612 is when this event was logged. The default format for date/time display (shown above) is like ISO8601 or RFC 3339 . If you need more control over the formatting of the date/time, provide a datefmt argument to$_{basicConfig}$, as in this example: 1.7 Displaying the date/time in messages 1.6 Changing the format of displayed messages