예제 #1
0
    def test_logger_api_config(self):
        '''Logger API config loads from the specified config objects'''
        logger = stackify.getLogger(config=self.config, auto_shutdown=False)
        self.loggers.append(logger)

        config = logger.handlers[0].listener.http.api_config

        self.assertEqual(config.application, 'test_appname')
        self.assertEqual(config.environment, 'test_environment')
        self.assertEqual(config.api_key, 'test_apikey')
        self.assertEqual(config.api_url, 'test_apiurl')
예제 #2
0
    def test_logger_api_config(self):
        '''Logger API config loads from the specified config objects'''
        logger = stackify.getLogger(config=self.config, auto_shutdown=False)
        self.loggers.append(logger)

        config = logger.handlers[0].listener.transport._api_config

        self.assertEqual(config.application, 'test_appname')
        self.assertEqual(config.environment, 'test_environment')
        self.assertEqual(config.api_key, 'test_apikey')
        self.assertEqual(config.api_url, 'test_apiurl')
예제 #3
0
    def test_get_logger_defaults(self):
        '''The logger has sane defaults'''
        env_map = {
            'STACKIFY_APPLICATION': 'test2_appname',
            'STACKIFY_ENVIRONMENT': 'test2_environment',
            'STACKIFY_API_KEY': 'test2_apikey',
        }

        with patch.dict('os.environ', env_map):
            logger = stackify.getLogger(auto_shutdown=False)
            self.loggers.append(logger)

        handler = logger.handlers[0]
        config = handler.listener.transport._api_config

        self.assertEqual(logger.name, 'tests.test_init')
        self.assertEqual(config.api_url, stackify.constants.API_URL)
        self.assertEqual(handler.listener.max_batch, stackify.constants.MAX_BATCH)
        self.assertEqual(handler.queue.maxsize, stackify.constants.QUEUE_SIZE)
예제 #4
0
    def test_logger_no_config(self):
        '''Logger API config loads from the environment automatically'''
        env_map = {
            'STACKIFY_APPLICATION': 'test2_appname',
            'STACKIFY_ENVIRONMENT': 'test2_environment',
            'STACKIFY_API_KEY': 'test2_apikey',
            'STACKIFY_API_URL': 'test2_apiurl',
        }

        with patch.dict('os.environ', env_map):
            logger = stackify.getLogger(auto_shutdown=False)
            self.loggers.append(logger)

        config = logger.handlers[0].listener.transport._api_config

        self.assertEqual(config.application, 'test2_appname')
        self.assertEqual(config.environment, 'test2_environment')
        self.assertEqual(config.api_key, 'test2_apikey')
        self.assertEqual(config.api_url, 'test2_apiurl')
예제 #5
0
    def test_get_logger_defaults(self):
        '''The logger has sane defaults'''
        env_map = {
            'STACKIFY_APPLICATION': 'test2_appname',
            'STACKIFY_ENVIRONMENT': 'test2_environment',
            'STACKIFY_API_KEY': 'test2_apikey',
        }

        with patch.dict('os.environ', env_map):
            logger = stackify.getLogger(auto_shutdown=False)
            self.loggers.append(logger)

        handler = logger.handlers[0]
        config = handler.listener.http.api_config

        self.assertEqual(logger.name, 'tests.test_init')
        self.assertEqual(config.api_url, stackify.constants.API_URL)
        self.assertEqual(handler.listener.max_batch, stackify.constants.MAX_BATCH)
        self.assertEqual(handler.queue.maxsize, stackify.constants.QUEUE_SIZE)
예제 #6
0
    def test_logger_no_config(self):
        '''Logger API config loads from the environment automatically'''
        env_map = {
            'STACKIFY_APPLICATION': 'test2_appname',
            'STACKIFY_ENVIRONMENT': 'test2_environment',
            'STACKIFY_API_KEY': 'test2_apikey',
            'STACKIFY_API_URL': 'test2_apiurl',
        }

        with patch.dict('os.environ', env_map):
            logger = stackify.getLogger(auto_shutdown=False)
            self.loggers.append(logger)

        config = logger.handlers[0].listener.http.api_config

        self.assertEqual(config.application, 'test2_appname')
        self.assertEqual(config.environment, 'test2_environment')
        self.assertEqual(config.api_key, 'test2_apikey')
        self.assertEqual(config.api_url, 'test2_apiurl')
예제 #7
0
 def test_logger_atexit(self, func):
     '''Logger registers an atexit function to clean up'''
     logger = stackify.getLogger(config=self.config)
     self.loggers.append(logger)
     func.assert_called_with(stackify.stopLogging, logger)
예제 #8
0
 def test_get_logger_reuse(self):
     '''Grabbing a logger twice results in the same logger'''
     logger = stackify.getLogger(config=self.config, auto_shutdown=False)
     self.loggers.append(logger)
     logger_two = stackify.getLogger(config=self.config, auto_shutdown=False)
     self.assertIs(logger_two, logger)
예제 #9
0
 def test_get_handlers(self):
     '''Registered handlers are provided by getHandlers'''
     logger = stackify.getLogger(config=self.config, auto_shutdown=False)
     self.loggers.append(logger)
     self.assertEqual(logger.handlers, stackify.getHandlers(logger))
예제 #10
0
 def test_logger_atexit(self, func):
     '''Logger registers an atexit function to clean up'''
     logger = stackify.getLogger(config=self.config)
     self.loggers.append(logger)
     func.assert_called_with(stackify.stopLogging, logger)
예제 #11
0
 def test_get_logger_reuse(self):
     '''Grabbing a logger twice results in the same logger'''
     logger = stackify.getLogger(config=self.config, auto_shutdown=False)
     self.loggers.append(logger)
     logger_two = stackify.getLogger(config=self.config, auto_shutdown=False)
     self.assertIs(logger_two, logger)
예제 #12
0
 def test_get_handlers(self):
     '''Registered handlers are provided by getHandlers'''
     logger = stackify.getLogger(config=self.config, auto_shutdown=False)
     self.loggers.append(logger)
     self.assertEqual(logger.handlers, stackify.getHandlers(logger))