예제 #1
0
    def test_verbose(self):
        config = LoggerConfig()
        set_up_logger(verbose=True, config=config)

        logger = logging.getLogger('gmailsync')

        self.assertEqual(logger.level, logging.DEBUG)
        self.assertEqual(len(logger.handlers), 1)
        self._verify_console_handler(logger.handlers[0], DEFAULT_LOG_FORMAT)
예제 #2
0
    def test_custom_format(self, mock_open):
        config = LoggerConfig(file='/gmailsync.log', format='%(message)s')
        set_up_logger(verbose=False, config=config)

        logger = logging.getLogger('gmailsync')

        self.assertEqual(logger.level, logging.INFO)
        self.assertEqual(len(logger.handlers), 2)
        self._verify_console_handler(logger.handlers[0], '%(message)s')
        self._verify_file_handler(logger.handlers[1], '/gmailsync.log',
                                  DEFAULT_LOG_MAX_BYTES,
                                  DEFAULT_LOG_BACKUP_COUNT, '%(message)s')
예제 #3
0
    def test_file_with_default_config(self, mock_open):
        config = LoggerConfig(file='/gmailsync.log')
        set_up_logger(verbose=True, config=config)

        logger = logging.getLogger('gmailsync')

        self.assertEqual(logger.level, logging.DEBUG)
        self.assertEqual(len(logger.handlers), 2)
        self._verify_console_handler(logger.handlers[0], DEFAULT_LOG_FORMAT)
        self._verify_file_handler(logger.handlers[1], '/gmailsync.log',
                                  DEFAULT_LOG_MAX_BYTES,
                                  DEFAULT_LOG_BACKUP_COUNT, DEFAULT_LOG_FORMAT)
예제 #4
0
    def test_file_with_customn_config(self, mock_open):
        config = LoggerConfig(file='/gmailsync.log',
                              max_bytes=50,
                              backup_count=3)
        set_up_logger(verbose=True, config=config)

        logger = logging.getLogger('gmailsync')

        self.assertEqual(logger.level, logging.DEBUG)
        self.assertEqual(len(logger.handlers), 2)
        self._verify_console_handler(logger.handlers[0], DEFAULT_LOG_FORMAT)
        self._verify_file_handler(logger.handlers[1], '/gmailsync.log', 50, 3,
                                  DEFAULT_LOG_FORMAT)