本文整理匯總了Python中logbook.FileHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python logbook.FileHandler方法的具體用法?Python logbook.FileHandler怎麽用?Python logbook.FileHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類logbook
的用法示例。
在下文中一共展示了logbook.FileHandler方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_logbook
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import FileHandler [as 別名]
def setup_logbook(logfile, logfile_kwargs=None):
"""Return a basic `logbook` setup which logs to `stderr` and to file."""
if logfile_kwargs is None:
logfile_kwargs = {}
logfile_kwargs.setdefault('level', 'DEBUG')
logfile_kwargs.setdefault('mode', 'w')
logfile_kwargs.setdefault('bubble', True)
logfile_kwargs.setdefault('format_string',
('--------------------------------------------------------------------------\n'
'[{record.time} {record.level_name:<8s} {record.channel:>10s}]'
' {record.filename:s}:{record.lineno:d}\n{record.message:s}'))
logbook_setup = logbook.NestedSetup([
logbook.NullHandler(),
logbook.more.ColorizedStderrHandler(level='INFO', bubble=False,
format_string='[{record.level_name:<8s} {record.channel:s}] {record.message:s}'),
logbook.FileHandler(logfile, **logfile_kwargs),
])
return logbook_setup
示例2: init_logging_file
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import FileHandler [as 別名]
def init_logging_file(filename, log_level='notset', rotate_log=True, rotate_max_size=10485760,
bubble=True):
log_dir = os.path.dirname(filename)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
if rotate_log is True:
handler = logbook.RotatingFileHandler(filename, level=figure_out_log_level(log_level),
max_size=int(rotate_max_size), bubble=bubble)
else:
handler = logbook.FileHandler(filename, level=figure_out_log_level(log_level),
bubble=bubble)
handler.push_application()
get_logger().debug("file based logging initialized in directory: " + log_dir)
示例3: setup_logger
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import FileHandler [as 別名]
def setup_logger(test, path='test.log'):
test.log_handler = FileHandler(path)
test.log_handler.push_application()
示例4: logging_context
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import FileHandler [as 別名]
def logging_context(path=None, level=None):
from logbook import StderrHandler, FileHandler
from logbook.compat import redirected_logging
with StderrHandler(level=level or 'INFO').applicationbound():
if path:
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
with FileHandler(path, bubble=True).applicationbound():
with redirected_logging():
yield
else:
with redirected_logging():
yield