我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用logging.disable()。
def setUp(self): """Initialize the framework for testing.""" self.uniprotid = "P00439" self.pdbid = "2pah" self.cathid = "1.50.10.100_1318" self.pfamid = "PF08124" self.config = c self.tmp = c.db_root self.fetch_from_url_or_retry = fetch_from_url_or_retry self.fetch_summary_properties_pdbe = fetch_summary_properties_pdbe self.get_preferred_assembly_id = get_preferred_assembly_id self.download_structure_from_pdbe = download_structure_from_pdbe self.download_sifts_from_ebi = download_sifts_from_ebi self.download_data_from_uniprot = download_data_from_uniprot self.download_alignment_from_cath = download_alignment_from_cath self.download_alignment_from_pfam = download_alignment_from_pfam self.downloads = downloads self.file_downloader = file_downloader logging.disable(logging.CRITICAL)
def tearDown(self): """Remove testing framework.""" self.uniprotid = None self.pdbid = None self.cathid = None self.pfamid = None self.config = None self.tmp = None self.fetch_from_url_or_retry = None self.fetch_summary_properties_pdbe = None self.get_preferred_assembly_id = None self.download_structure_from_pdbe = None self.download_sifts_from_ebi = None self.download_data_from_uniprot = None self.download_alignment_from_cath = None self.download_alignment_from_pfam = None self.downloads = None self.file_downloader = None logging.disable(logging.NOTSET)
def test_ascii_in_unicode_out(self): # ASCII input is converted to Unicode. The original_encoding # attribute is set to 'utf-8', a superset of ASCII. chardet = bs4.dammit.chardet_dammit logging.disable(logging.WARNING) try: def noop(str): return None # Disable chardet, which will realize that the ASCII is ASCII. bs4.dammit.chardet_dammit = noop ascii = b"<foo>a</foo>" soup_from_ascii = self.soup(ascii) unicode_output = soup_from_ascii.decode() self.assertTrue(isinstance(unicode_output, str)) self.assertEqual(unicode_output, self.document_for(ascii.decode())) self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8") finally: logging.disable(logging.NOTSET) bs4.dammit.chardet_dammit = chardet
def setUp(self): # disable logging while testing logging.disable(logging.CRITICAL) self.patched = {} if hasattr(self, 'patch_these'): for patch_this in self.patch_these: namespace = patch_this[0] if isinstance(patch_this, (list, set)) else patch_this patcher = mock.patch(namespace) mocked = patcher.start() mocked.reset_mock() self.patched[namespace] = mocked if isinstance(patch_this, (list, set)) and len(patch_this) > 0: retval = patch_this[1] if callable(retval): retval = retval() mocked.return_value = retval
def test_ascii_in_unicode_out(self): # ASCII input is converted to Unicode. The original_encoding # attribute is set to 'utf-8', a superset of ASCII. chardet = bs4.dammit.chardet_dammit logging.disable(logging.WARNING) try: def noop(str): return None # Disable chardet, which will realize that the ASCII is ASCII. bs4.dammit.chardet_dammit = noop ascii = b"<foo>a</foo>" soup_from_ascii = self.soup(ascii) unicode_output = soup_from_ascii.decode() self.assertTrue(isinstance(unicode_output, unicode)) self.assertEqual(unicode_output, self.document_for(ascii.decode())) self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8") finally: logging.disable(logging.NOTSET) bs4.dammit.chardet_dammit = chardet
def test_unauthorized(self): self._stub_nova_api_calls_unauthorized( self.exceptions.nova_unauthorized) self.mox.ReplayAll() url = reverse('horizon:project:overview:index') # Avoid the log message in the test # when unauthorized exception will be logged logging.disable(logging.ERROR) res = self.client.get(url) logging.disable(logging.NOTSET) self.assertEqual(302, res.status_code) self.assertEqual(('Location', settings.TESTSERVER + settings.LOGIN_URL + '?' + REDIRECT_FIELD_NAME + '=' + url), res._headers.get('location', None),)
def test_instance_details_unauthorized(self): server = self.servers.first() api.nova.server_get(IsA(http.HttpRequest), server.id)\ .AndRaise(self.exceptions.nova_unauthorized) self.mox.ReplayAll() url = reverse('horizon:project:instances:detail', args=[server.id]) # Avoid the log message in the test # when unauthorized exception will be logged logging.disable(logging.ERROR) res = self.client.get(url) logging.disable(logging.NOTSET) self.assertEqual(302, res.status_code) self.assertEqual(('Location', settings.TESTSERVER + settings.LOGIN_URL + '?' + REDIRECT_FIELD_NAME + '=' + url), res._headers.get('location', None),)
def setup_logging(debugging): """ configures logging """ # configure logging formatting = '%(asctime)s | %(levelname)s | %(funcName)s | %(message)s' log_file = 'logs/{0}.log'.format(time.strftime("%d.%m.%Y %H-%M")) logging.basicConfig(level=logging.DEBUG, format=formatting) # disable all non-error messages if not debugging if not debugging: logging.disable(logging.DEBUG) # setup output streams rootLogger = logging.getLogger() # file output logFormatter = logging.Formatter(formatting) fileHandler = logging.FileHandler("{0}".format(log_file)) fileHandler.setFormatter(logFormatter) rootLogger.addHandler(fileHandler) # terminal output # consoleHandler = logging.StreamHandler() # consoleHandler.setFormatter(logFormatter) # rootLogger.addHandler(consoleHandler)
def SuppressLogging(level=logging.ERROR): """Momentarilly suppress logging events from all loggers. TODO(jbudorick): This is not thread safe. Log events from other threads might also inadvertently disappear. Example: with logging_utils.SuppressLogging(): # all but CRITICAL logging messages are suppressed logging.info('just doing some thing') # not shown logging.critical('something really bad happened') # still shown Args: level: logging events with this or lower levels are suppressed. """ logging.disable(level) yield logging.disable(logging.NOTSET)
def my_log(): logging.basicConfig(level=logging.INFO, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', handlers=[logging.FileHandler('message.log', 'a', 'utf-8')]) # ?????_?????__ _log = logging.getLogger('app.' + __name__) host = '10.0.0.175' port = 8080 # ??? 'xxxx' % (aa, bb)???????? _log.error('error to connect to %s:%d', host, port) _log.addFilter(FilterFunc('foo')) # ?????foo()??????? lgg = logging.getLogger('app.network.client') lgg.propagate = False # ?????? lgg.error('do you see me?') # ???????? lgg.setLevel(logging.CRITICAL) lgg.error('now you see me?') logging.disable(logging.DEBUG) # ???????? # ??log??????main????????? config.fileConfig('applogcfg.ini')
def SuppressLogging(level=logging.ERROR): """Momentarilly suppress logging events from all loggers. TODO(jbudorick): This is not thread safe. Log events from other threads might also inadvertently dissapear. Example: with logging_utils.SuppressLogging(): # all but CRITICAL logging messages are suppressed logging.info('just doing some thing') # not shown logging.critical('something really bad happened') # still shown Args: level: logging events with this or lower levels are suppressed. """ logging.disable(level) yield logging.disable(logging.NOTSET)
def check_passphrase(): rpc = get_rpc() logging.disable(logging.DEBUG) rpc.walletpassphrase(wallet_passphrase, int(config.rpc_config['timeout'])) logging.disable(logging.NOTSET) # let some daemon time to unlock wallet time.sleep(1) # check wallet_info = rpc.getwalletinfo() if wallet_info['unlocked_until'] < time.time(): bot_logger.logger.error("error durring unlock your wallet") exit() rpc.walletlock()
def execute(self, context): if self.cmd == sym.LIST: print('database relations:') for table in context.db.list(): attrs = ['{}:{}'.format(attr, type.value)\ for attr, type in context.db.describe(table)] print(' {}({})'.format(table, ', '.join(attrs))) if len(context.views.list()) > 0: print('views defined:') for view in context.views.list(): raw_def = context.views.raw_def(view) ast = RelExpr.from_view_def(raw_def) logging.disable(logging.WARNING) ast.validate(context) logging.disable(logging.NOTSET) print(' {}({}) {} {}'.format(view, ', '.join(ast.type.str_attr_names_and_types()), literal(sym.GETS), raw_def)) elif self.cmd == sym.QUIT: sys.exit(0)
def configure_logger(log_level): """Configure the program's logger. :param log_level: Log level for configuring logging :type log_level: str :rtype: None """ if log_level is None: logging.disable(logging.CRITICAL) return None if log_level in constants.VALID_LOG_LEVEL_VALUES: logging.basicConfig( format=('%(threadName)s: ' '%(asctime)s ' '%(pathname)s:%(funcName)s:%(lineno)d - ' '%(message)s'), stream=sys.stderr, level=log_level.upper()) return None msg = 'Log level set to an unknown value {!r}. Valid values are {!r}' raise DCOSException( msg.format(log_level, constants.VALID_LOG_LEVEL_VALUES))
def test_process_msg_exception(self): """ Tests the process_msg function when an exception is raised. """ logging.disable(logging.NOTSET) with patch('receiver.receiver.logging.getLogger', return_value=LOGGER): with patch('receiver.receiver.json.loads', side_effect=Exception('foo')): with LogCapture() as log_capture: process_msg(**self.kwargs) log_capture.check( ('receiver', 'ERROR', 'An error occurred while processing the message \'{"@uuid": "12345", ' '"collection": "elasticsearch.test_index.test_logs", "message": ' '"foobar"}\':\n' ' foo'), )
def setUp(self): super(L3OpenContrailTestCases, self).setUp() logging.disable(logging.CRITICAL)
def tearDown(self): super(L3OpenContrailTestCases, self).tearDown() logging.disable(logging.NOTSET)
def setUp(self): super(ApiRequestsTestCases, self).setUp() logging.disable(logging.CRITICAL)
def tearDown(self): super(ApiRequestsTestCases, self).tearDown() logging.disable(logging.NOTSET)
def setUp(self): super(ApiCrudTestCases, self).setUp() logging.disable(logging.CRITICAL)
def setUp(self): super(ErrorTestCases, self).setUp() logging.disable(logging.CRITICAL)
def tearDown(self): super(ErrorTestCases, self).tearDown() logging.disable(logging.NOTSET)
def setUp(self): super(NetworkTestCases, self).setUp() logging.disable(logging.CRITICAL)
def tearDown(self): super(NetworkTestCases, self).tearDown() logging.disable(logging.NOTSET)
def setUp(self): super(SubnetTestCases, self).setUp() logging.disable(logging.CRITICAL)
def setUp(self): super(SecurityGroupTestCases, self).setUp() logging.disable(logging.CRITICAL)
def tearDown(self): super(SecurityGroupTestCases, self).tearDown() logging.disable(logging.NOTSET)