def test_configure_log_file_rotate_each(self): """ Check file rotation archive keeping. """ file_name, segments = manufacture.fs.makePathInTemp() content = ( u'[log]\n' u'log_file: %s\n' u'log_file_rotate_external: No\n' u'log_file_rotate_each: 2 hours\n' u'log_file_rotate_count: 3\n' ) % (file_name) configuration = self.getConfiguration(content=content) logger = manufacture.makeLogger() try: logger.configure(configuration) handler = logger._active_handlers['file'] self.assertIsInstance(TimedRotatingFileHandler, handler) self.assertEqual(3, handler.backupCount) self.assertEqual(u'H', handler.when) self.assertEqual(2 * 60 * 60, handler.interval) self.assertEqual( (u'Time base rotated file %s at (2, u\'h\') ' u'keeping 3 rotated archives' % (file_name)), handler.name, ) logger.removeAllHandlers() finally: manufacture.fs.deleteFile(segments)
def test_configure_log_file_rotate_at_size(self): """ Check file rotation at size. """ file_name, segments = manufacture.fs.makePathInTemp() content = ( u'[log]\n' u'log_file: %s\n' u'log_file_rotate_external: No\n' u'log_file_rotate_at_size: 100\n' u'log_file_rotate_count: 10\n' ) % (file_name) configuration = self.getConfiguration(content=content) logger = manufacture.makeLogger() try: logger.configure(configuration) handler = logger._active_handlers['file'] self.assertIsInstance(RotatingFileHandler, handler) self.assertEqual(10, handler.backupCount) self.assertEqual( (u'Size base rotated file %s at %s bytes ' u'keeping 10 rotated archives' % ( file_name, 100)), handler.name, ) logger.removeAllHandlers() finally: manufacture.fs.deleteFile(segments)
def test_configure_logger_file_permissions_unix(self): """ Integration test that the logger will initialize the log file using the account name. """ path, segments = manufacture.fs.makePathInTemp() content = ( '[log]\n' 'log_file: %s\n' ) % (path) config = self._getConfiguration(content=content) if self._drop_user != '-': account = self._drop_user else: account = manufacture.username logger = manufacture.makeLogger() try: logger.configure(configuration=config, account=account) logger.removeAllHandlers() self.assertTrue( manufacture.fs.exists(segments), 'Log file was not created at ' + path.encode('utf-8'), ) # FIXME:928: # Rather than testing for 2 variables, we should only check # for matching "account" and not "Administrators". self.assertIn( [unicode(account), 'Administrators'], manufacture.fs.getOwner(segments)) finally: manufacture.fs.deleteFile(segments, ignore_errors=True)
def test_configure_no_account(self): """ Integration test that logger will raise an exception if account does not exists. """ config = self._getConfiguration() account = u'no-such-account' logger = manufacture.makeLogger() with self.assertRaises(UtilsError) as context: logger.configure(configuration=config, account=account) self.assertEqual(u'1026', context.exception.event_id)
def test_configure_log_file_rotate_external(self): """ Check file rotation. """ file_name, segments = manufacture.fs.makePathInTemp() content = ( u'[log]\n' u'log_file: %s\n' u'log_file_rotate_external: Yes\n' ) % (file_name) configuration = self.getConfiguration(content=content) logger = manufacture.makeLogger() try: logger.configure(configuration) handler = logger._active_handlers['file'] self.assertIsInstance(WatchedFileHandler, handler) self.assertEqual( u'External rotated file %s' % (file_name), handler.name) logger.removeAllHandlers() finally: manufacture.fs.deleteFile(segments)
def setUp(self): super(TestLogger, self).setUp() log_name = manufacture.getUniqueString() self.config = self.getConfiguration() self.logger = manufacture.makeLogger(log_name=log_name)