我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用logging.VERBOSE。
def init_logger(self, args): level = logging.INFO if args.verbose: level = logging.VERBOSE if args.debug: level = logging.DEBUG logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', level=level) Rthandler = RotatingFileHandler('arbitrage.log', maxBytes=100*1024*1024,backupCount=10) Rthandler.setLevel(level) formatter = logging.Formatter('%(asctime)-12s [%(levelname)s] %(message)s') Rthandler.setFormatter(formatter) logging.getLogger('').addHandler(Rthandler) logging.getLogger("requests").setLevel(logging.WARNING) logging.getLogger("urllib3").setLevel(logging.WARNING)
def checked(self, message, *args, **kws): # checked messages have level VERBOSE, but when is requested the command # rapydo check their level is increase to INFO level = logging.VERBOSE if hasattr(mem, 'action'): if mem.action == "check": level = logging.INFO if self.isEnabledFor(level): # Yes, logger takes its '*args' as 'args'. # message = "\u2713 %s" % message if self.disable_unicode: message = "(CHECKED) %s" % message elif self.colors_enabled: message = "\033[0;32m\u2713\033[0m %s" % message else: message = "\u2713 %s" % message self._log( # pylint:disable=protected-access level, message, args, **kws )
def prepare_logging(): global umap2_logger global stdio_handler if umap2_logger is None: def add_debug_level(num, name): def fn(self, message, *args, **kwargs): if self.isEnabledFor(num): self._log(num, message, args, **kwargs) logging.addLevelName(num, name) setattr(logging, name, num) return fn logging.Logger.verbose = add_debug_level(5, 'VERBOSE') logging.Logger.always = add_debug_level(100, 'ALWAYS') FORMAT = '[%(levelname)-6s] %(message)s' stdio_handler = logging.StreamHandler() stdio_handler.setLevel(logging.INFO) formatter = logging.Formatter(FORMAT) stdio_handler.setFormatter(formatter) umap2_logger = logging.getLogger('umap2') umap2_logger.addHandler(stdio_handler) umap2_logger.setLevel(logging.VERBOSE) return umap2_logger
def get_logger(self): levels = { 0: logging.INFO, 1: logging.DEBUG, # verbose is added by umap2.__init__ module 2: logging.VERBOSE, } verbose = self.options.get('--verbose', 0) logger = logging.getLogger('umap2') if verbose in levels: set_default_handler_level(levels[verbose]) else: set_default_handler_level(logging.VERBOSE) if self.options.get('--quiet', False): set_default_handler_level(logging.WARNING) return logger
def fuzzy_search(self, *filters): """ Perform a "fuzzy" search that matches the given characters in the given order. :param filters: The pattern(s) to search for. :returns: The matched password names (a list of strings). """ matches = [] logger.verbose("Performing fuzzy search on %s (%s) ..", pluralize(len(filters), "pattern"), concatenate(map(repr, filters))) patterns = list(map(create_fuzzy_pattern, filters)) for entry in self.entries: if all(p.search(entry.name) for p in patterns): matches.append(entry) logger.log(logging.INFO if matches else logging.VERBOSE, "Matched %s using fuzzy search.", pluralize(len(matches), "password")) return matches
def simple_search(self, *keywords): """ Perform a simple search for case insensitive substring matches. :param keywords: The string(s) to search for. :returns: The matched password names (a generator of strings). Only passwords whose names matches *all* of the given keywords are returned. """ matches = [] keywords = [kw.lower() for kw in keywords] logger.verbose("Performing simple search on %s (%s) ..", pluralize(len(keywords), "keyword"), concatenate(map(repr, keywords))) for entry in self.entries: normalized = entry.name.lower() if all(kw in normalized for kw in keywords): matches.append(entry) logger.log(logging.INFO if matches else logging.VERBOSE, "Matched %s using simple search.", pluralize(len(matches), "password")) return matches
def test_log(): # No handlers by default mylog = getLogger("test") assert isinstance(mylog, logger.Logger) assert mylog.name == "test" assert len(mylog.handlers) == 0 pkglog = getLogger("nicfit") assert isinstance(mylog, logger.Logger) assert pkglog.name == "nicfit" for log in [mylog, pkglog]: assert(log.propagate) assert(isinstance(log, logger.Logger)) with patch.object(log, "log") as mock_log: log.verbose("Honey's Dead") mock_log.assert_called_with(logging.VERBOSE, "Honey's Dead")
def cx(self, circuit, control_qubit, target_qubit, control, target): if target in self.__coupling_map[control]: logger.log(logging.VERBOSE, 'cx() - cnot: (%s, %s)', str(control), str(target)) circuit.cx(control_qubit, target_qubit) elif control in self.__coupling_map[target]: logger.log(logging.VERBOSE, 'cx() - inverse-cnot: (%s, %s)', str(control), str(target)) circuit.h(control_qubit) circuit.h(target_qubit) circuit.cx(target_qubit, control_qubit) circuit.h(control_qubit) circuit.h(target_qubit) else: logger.critical('cx() - Cannot connect qubit %s to qubit %s', str(control), str(target)) exit(3) # place cnot gates based on the path created in create_path method
def place_cx_(self, circuit, quantum_r, oracle='11'): if not oracle == '00': logger.log(logging.VERBOSE, 'place_cx() - oracle != 00') stop = self.__n_qubits // 2 for qubit in self.__connected: if self.__connected[qubit] != -1: if oracle == '11': logger.log(logging.VERBOSE, 'place_cx() - oracle = 11') self.cx(circuit, quantum_r[qubit], quantum_r[self.__connected[qubit]], qubit, self.__connected[qubit]) elif oracle == '10': logger.log(logging.VERBOSE, 'place_cx() - oracle = 10') if stop > 0: self.cx(circuit, quantum_r[qubit], quantum_r[self.__connected[qubit]], qubit, self.__connected[qubit]) stop -= 1 # place Hadamard gates
def place_x(self, circuit, quantum_r): sorted_c = sorted(self.__connected.items(), key=operator.itemgetter(0)) logger.log(logging.VERBOSE, 'place_x() - sorted_c:\n%s', str(sorted_c)) s_0 = self.__n_qubits // 2 i = 0 count = self.__n_qubits - 1 for qubit in sorted_c: if count <= 0: break if i >= s_0: circuit.x(quantum_r[qubit[0]]) else: circuit.iden(quantum_r[qubit[0]]) i += 1 i = 0 for qubit in sorted_c: if i >= s_0: circuit.iden(quantum_r[qubit[0]]) else: circuit.x(quantum_r[qubit[0]]) i += 1 # final measure
def inject_verbose_info(self): logging.VERBOSE = 15 logging.verbose = lambda x: logging.log(logging.VERBOSE, x) logging.addLevelName(logging.VERBOSE, "VERBOSE")
def logger_init(level = logging.INFO): logging.basicConfig(format = '%(name)s: %(levelname)s: %(message)s', level = level) logging.addLevelName(logging.VERBOSE, 'VERBOSE')
def log_verbose(self, message, *args, **kws): if self.isEnabledFor(logging.VERBOSE): self.log(logging.VERBOSE, message, *args, **kws)
def verbose(self, msg, *args, **kwargs): '''Log \a msg at 'verbose' level, debug < verbose < info''' self.log(logging.VERBOSE, msg, *args, **kwargs)
def verbose(self, message, *args, **kws): # Yes, logger takes its '*args' as 'args'. if self.isEnabledFor(VERBOSE): self._log( # pylint:disable=protected-access VERBOSE, message, args, **kws )
def checked_simple(self, message, *args, **kws): # checked messages have level VERBOSE, but when is requested the command # rapydo check their level is increase to INFO level = logging.VERBOSE if hasattr(mem, 'action'): if mem.action == "check": level = logging.INFO if self.isEnabledFor(level): message = "(CHECKED)\t%s" % message self._log( # pylint:disable=protected-access level, message, args, **kws )
def init_logger(self, args): level = logging.INFO if args.verbose: level = logging.VERBOSE if args.debug: level = logging.DEBUG logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', level=level)
def instantiate( cls, streamType = "SCREEN", logLevel = "INFO" ): try: logging.VERBOSE = 5 logging.addLevelName(logging.VERBOSE, "VERBOSE") logging.Logger.verbose = lambda inst, msg, *args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs) logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg, *args, **kwargs) cls.logger = logging.getLogger() if logLevel not in logging._levelNames: raise Exception( 'Invalid file level' ) cls.logger.setLevel( logging._levelNames[logLevel] ) streamType = app.config['STREAMTYPE'] if streamType == "SCREEN": stream = logging.StreamHandler() else: stream = logging.FileHandler( app.config['LOGFILE'] ) formatter = logging.Formatter( '[%(levelname)-7s - %(asctime)s] %(message)s' ) stream.setFormatter( formatter ) cls.logger.addHandler( stream ) except Exception, e: print( 'Unable to get/set log configurations. Error: %s'%( e ) ) cls.logger = None ## # Records a message in a file and/or displays it in the screen. # @param level - String containing the name of the log message. # @param message - String containing the message to be recorded. #
def verbose( cls, message ): cls.log("VERBOSE", message, Log.getCallers( inspect.stack() )) ## # Gets the data about the caller of the log method. # @param stack Array containing the system calling stack. # @return Array containing the caller class name and the caller method, respectively. #
def test_logLevelArguments(): p = ArgumentParser(add_log_args=True) # Invalids for args, Exc in [(["-l"], SystemExit), (["--log-level"], SystemExit), (["-l", "Vision-InTheBlinkOfAnEye"], ValueError), (["-l", "debug:TheOnlyOne"], ValueError), ]: with pytest.raises(Exc): p.parse_args(args) # Level sets on root logger. for args, level in [(["-l", "debug"], logging.DEBUG), (["-lerror"], logging.ERROR), (["--log-level", "warning"], logging.WARN), (["--log-level=critical"], logging.CRITICAL), (["--log-level=verbose"], logging.VERBOSE), ]: p.parse_args(args) logger = getLogger() assert logger.getEffectiveLevel() == level # Level sets on other logger. for args, level, log in [ (["-l", "Venom:debug"], logging.DEBUG, "Venom"), (["-lWatain:eRroR"], logging.ERROR, "Watain"), (["--log-level", "l1:WARNING"], logging.WARN, "l1"), (["--log-level=nicfit:critical"], logging.CRITICAL, "nicfit"), (["--log-level=eyeD3:verbose"], logging.VERBOSE, "eyeD3"), ]: logger = getLogger(log) with patch.object(logger, "setLevel") as mock_log: p.parse_args(args) mock_log.assert_called_with(level)
def verbose(self, msg, *args, **kwargs): """Log msg at 'verbose' level, debug < verbose < info""" self.log(logging.VERBOSE, msg, *args, **kwargs)
def __init__(self): logging.StreamHandler.__init__(self) logging.addLevelName(logging.VERBOSE, "VERBOSE") formatter = logging.Formatter('%(filename)s - %(levelname)s - %(message)s') self.setFormatter(formatter)
def test_verbose_hack(self): self.logger.verbose("foo") logging.verbose("foo") self.assertEqual(logging.VERBOSE, 15) if six.PY2: # There is no _levelNames attribute in Python 3 self.assertTrue("VERBOSE" in logging._levelNames) self.assertEqual(logging.getLevelName(15), "VERBOSE")
def verbose(self, msg, *args, **kwargs): """ Log 'msg % args' with severity 'VERBOSE'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.info("Houston, we have a %s", "interesting problem", exc_info=1) """ if self.manager.disable >= logging.VERBOSE: return if logging.VERBOSE >= self.getEffectiveLevel(): self._log(*(logging.VERBOSE, msg, args), **kwargs)
def verbose(msg, *args, **kwargs): """ Log a message with severity 'VERBOSE' on the root logger. """ if len(logging.root.handlers) == 0: logging.basicConfig() logging.root.verbose(*((msg, ) + args), **kwargs)
def log_verbose(self, msg, *args, **kwargs): self.__log(logging.VERBOSE, msg, *args, **kwargs)