Python logbook.FileHandler() Examples
The following are 4
code examples of logbook.FileHandler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
logbook
, or try the search function
.
Example #1
Source File: utils.py From stethoscope with Apache License 2.0 | 6 votes |
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
Example #2
Source File: common.py From postgresql-metrics with Apache License 2.0 | 5 votes |
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)
Example #3
Source File: core.py From zipline-chinese with Apache License 2.0 | 5 votes |
def setup_logger(test, path='test.log'): test.log_handler = FileHandler(path) test.log_handler.push_application()
Example #4
Source File: __init__.py From srep with GNU General Public License v3.0 | 5 votes |
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