Ejemplo n.º 1
0
    def test_get_stream_name_method(self):
        AppLogger.config_dict = None
        self.assertEqual(None, AppLogger.get_stream_name())

        AppLogger.config_dict = {
            'handlers': {
                'watchtower': {
                    'stream_name': 'test'
                }
            }
        }
        self.assertEqual('test', AppLogger.get_stream_name())

        AppLogger.config_dict = {'handlers': ''}
        self.assertEqual(None, AppLogger.get_stream_name())

        AppLogger.config_dict = {'handlers': {'watchtower': ''}}
        self.assertEqual(None, AppLogger.get_stream_name())

        AppLogger.config_dict = {
            'handlers': {
                'watchtower': {
                    'stream_name': 'test2'
                }
            }
        }
        self.assertNotEqual('test', AppLogger.get_stream_name())
Ejemplo n.º 2
0
    def test_3__configure_logger_method(self):
        AppLogger.logger = logging.getLogger('test_configure_3')
        AppLogger.logger.level = logging.DEBUG
        AppLogger.config_dict = None

        with LogCapture() as lc:
            AppLogger._configure_logger(
                AppLoggerJsonConfigName.default_with_watchtower_format_1(),
                'test_log_group', 'test_log_stream')
            lc.check_present(
                ('test_configure_3', 'DEBUG',
                 'Getting Config Section for [default_with_watchtower_format_1]'
                 ),
                ('test_configure_3', 'DEBUG',
                 "Set logging configuration to: {'version': 1, 'disable_existing_loggers': 'false', 'formatters': {'default-single-line': {'style': '{', 'datefmt': '%Y-%m-%dT%H:%M:%S', 'format': '[{asctime:s}.{msecs:3.0f}] | {client_ip} | {host_name} | {levelname:8s} | {name:<10s} | {funcName:<10s} | {lineno:4d} | {message:s}'}}, 'handlers': {'console': {'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'default-single-line', 'stream': 'ext://sys.stdout'}, 'watchtower': {'level': 'DEBUG', 'class': 'watchtower.CloudWatchLogHandler', 'formatter': 'default-single-line', 'log_group': 'default_with_watchtower_format_1', 'stream_name': 'default', 'send_interval': 1, 'create_log_group': 'True'}}, 'loggers': {}, 'root': {'handlers': ['console', 'watchtower']}}"
                 ),
            )
            self.assertEqual('test_log_group', AppLogger.get_log_group())
            self.assertEqual('test_log_stream', AppLogger.get_stream_name())