(self, config)
return result
Configure a formatter from a dictionary.
Configure a formatter from a dictionary.
Configure a formatter from a dictionary .
def configure_formatter(self, config):
        """Configure a formatter from a dictionary."""
        if '()' in config:
            factory = config['()'] # for use in exception handler
            try:
                result = self.configure_custom(config)
            except TypeError as te:
                if "'format'" not in str(te):
                    raise
                #Name of parameter changed from fmt to format.
                #Retry with old name.
                #This is so that code can be used with older Python versions
                #(e.g. by Django)
                config['fmt'] = config.pop('format')
                config['()'] = factory
                result = self.configure_custom(config)
        else:
            fmt = config.get('format', None)
            dfmt = config.get('datefmt', None)
            style = config.get('style', '%')
            cname = config.get('class', None)

            if not cname:
                c = logging.Formatter
            else:
                c = _resolve(cname)

            # A TypeError would be raised if "validate" key is passed in with a formatter callable
            # that does not accept "validate" as a parameter
            if 'validate' in config:  # if user hasn't mentioned it, the default will be fine
                result = c(fmt, dfmt, style, config['validate'])
            else:
                result = c(fmt, dfmt, style)

        return result
def configure_formatter ( self , config ) : if '()' in config : factory = config [ '()' ] # for use in exception handler try : result = self . configure_custom ( config ) except TypeError as te : if "'format'" not in str ( te ) : raise #Name of parameter changed from fmt to format. #Retry with old name. #This is so that code can be used with older Python versions #(e.g. by Django) config [ 'fmt' ] = config . pop ( 'format' ) config [ '()' ] = factory result = self . configure_custom ( config ) else : fmt = config . get ( 'format' , None ) dfmt = config . get ( 'datefmt' , None ) style = config . get ( 'style' , '%' ) cname = config . get ( 'class' , None ) if not cname : c = logging . Formatter else : c = _resolve ( cname ) # A TypeError would be raised if "validate" key is passed in with a formatter callable # that does not accept "validate" as a parameter if 'validate' in config : # if user hasn't mentioned it, the default will be fine result = c ( fmt , dfmt , style , config [ 'validate' ] ) else : result = c ( fmt , dfmt , style ) return result