我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用logging.logProcesses()。
def test_optional(self): r = logging.makeLogRecord({}) NOT_NONE = self.assertIsNotNone if threading: NOT_NONE(r.thread) NOT_NONE(r.threadName) NOT_NONE(r.process) NOT_NONE(r.processName) log_threads = logging.logThreads log_processes = logging.logProcesses log_multiprocessing = logging.logMultiprocessing try: logging.logThreads = False logging.logProcesses = False logging.logMultiprocessing = False r = logging.makeLogRecord({}) NONE = self.assertIsNone NONE(r.thread) NONE(r.threadName) NONE(r.process) NONE(r.processName) finally: logging.logThreads = log_threads logging.logProcesses = log_processes logging.logMultiprocessing = log_multiprocessing
def config_logging(level=LEVEL, prefix=PREFIX, other_loggers=None): # Little speed up if "%(process)d" not in prefix: logging.logProcesses = False if "%(processName)s" not in prefix: logging.logMultiprocessing = False if "%(thread)d" not in prefix and "%(threadName)s" not in prefix: logging.logThreads = False handler = logging.StreamHandler() handler.setFormatter(LogFormatter()) loggers = [logging.getLogger('pyftpdlib')] if other_loggers is not None: loggers.extend(other_loggers) for logger in loggers: logger.setLevel(level) logger.addHandler(handler)
def configlog4download(logger, db_session, download_id, isterminal): """configs for download and returns the handler used to store the log to the db and to a tmp file. The file is accessible via logger..baseFilename """ # https://docs.python.org/2/howto/logging.html#optimization: logging._srcfile = None logging.logThreads = 0 logging.logProcesses = 0 # FIXME above: move elsewhere (maybe restoring defaults?) logger.setLevel(logging.INFO) # necessary to forward to handlers # custom StreamHandler: count errors and warnings: dbstream_handler = DbStreamHandler(db_session, download_id) logger.addHandler(dbstream_handler) if isterminal: # configure print to stdout (by default only info and critical messages) logger.addHandler(SysOutStreamHandler(sys.stdout)) return dbstream_handler # def configlog4stdout(logger): # logger.setLevel(logging.INFO) # necessary to forward to handlers # # configure print to stdout (by default only info and critical messages): # logger.addHandler(SysOutStreamHandler(sys.stdout))
def setup(mute_stdout=False): # logging.basicConfig() if mute_stdout: handler = logging.NullHandler() else: formatter_str = '%(asctime)s %(levelname)s %(message)s' handler = logging.StreamHandler() handler.setFormatter(logging.Formatter(formatter_str)) # Add handler to logger logger = logging.getLogger(_product_name) logger.addHandler(handler) # disable unnecessary information capture logging.logThreads = 0 logging.logProcesses = 0 # to make sure each log record does not have a source file name attached # pylint: disable=protected-access logging._srcfile = None # pylint: enable=protected-access