(continued from previous page) 'filters': { 'myfilter': { '() ': MyFilter, 'param':'noshow', } }, 'handlers': { 'console': { 'class':'logging.StreamHandler ', 'filters': ['myfilter'] } }, 'root': { 'level ':'DEBUG', 'handlers': ['console'] }, } if __name__ =='__main__ ': logging.config.dictConfig(LOGGING) logging.debug( 'hello') logging.debug( 'hello - noshow') This example shows how you can pass configuration data to the callable which constructs the instance, in the form of keyword parameters. When run, the above script will print: changed: hello which shows that the filter is working as configured. A couple of extra points to note: • If you can’t refer to the callable directly in the configuration (e.g. if it lives in a different module, and you can’t import it directly where the configuration dictionary is), you can use the form ext://... as de- scribed in logging-config-dict-externalobj. For example, you could have used the text$_{'ext://__main__.}$ $_{MyFilter'}$instead of$_{MyFilter}$ in the above example. • As well as for filters, this technique can also be used to configure custom handlers and formatters. See logging- config-dict-userdef for more information on how logging supports using user-defined objects in its configura- tion, and see the other cookbook recipe Customizing handlers with dictConfig() above. 23 Customized exception formatting There might be times when you want to do customized exception formatting - for argument’s sake, let’s say you want exactly one line per logged event, even when exception information is present. You can do this with a custom formatter class, as shown in the following example: (continues on next page) 34 import logging classOneLineExceptionFormatter (logging .Formatter): def formatException (self, exc_info): """ Format an exception so that it prints on a single line. """ result=super() .formatException(exc_info) return repr(result) # or format into one line however you want to def format(self, record): s =super() .format(record)