Python logging 模块,logProcesses() 实例源码
我们从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 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 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 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。