Ejemplo n.º 1
0
def getRootLogger(level, syslog):
    """Configures our Python stdlib Root Logger"""
    # Convert the supplied log level string
    # into a valid log level constant
    level_string = 'logging.%s' % level.upper()
    level_constant = utils.strToClass(level_string)

    # Set up the logger now
    return utils.setupLogger(level=level_constant, syslog=syslog)
Ejemplo n.º 2
0
    def _getTranslator(self, name):
        """Returns a Translator object.

        Returns a fully built Translator object based on the config supplied.
        As long as a subclassed Config object does not add any additional
        custom fields, this method can be used as-is.

        args:
            name: String representing the name of the translator

        returns:
            A Translator object built with the config parameters returned by
            self._getTranslatorConfig().
        """
        # Get the configuration for a supplied Translator definition.
        config = self._getTranslatorConfig(name)
        class_string = config['translator']

        # There are a few parameters that are stored for each Translator
        # definition that we do not pass in as arguments to the __init__()
        # method:
        #
        # type: This is an internal config value used to distinguish between
        #       Hook and Translator configs.
        #
        # translator: This is an internal config value that defines the class
        #             and package name used to instantiate a new Translator.
        del config['type']
        del config['translator']

        # Now instantiate the class and return it.
        try:
            return utils.strToClass(class_string)(**config)
        except AttributeError:
            raise ConfigException('Unable to convert "%s" to a proper object'
                                  % class_string)
Ejemplo n.º 3
0
def getConfigObject(config_module, config_file):
    """Constructs and returns a Config object"""
    config_class = utils.strToClass(config_module)
    config_object = config_class(config_file)
    return config_object
Ejemplo n.º 4
0
 def testStrToClass(self):
     """Test the strToClass() method"""
     class_string_name = 'tornado.testing.AsyncTestCase'
     returned_class = utils.strToClass(class_string_name)
     self.assertEquals(testing.AsyncTestCase, returned_class)