Python logbook.StreamHandler() Examples
The following are 24
code examples of logbook.StreamHandler().
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: log_service.py From cookiecutter-course with GNU General Public License v2.0 | 6 votes |
def global_init(log_level_text, filename): level = LogService.__get_logbook_logging_level(log_level_text) if not filename: logbook.StreamHandler(sys.stdout, level=level).push_application() else: logbook.TimedRotatingFileHandler( filename, level=level, date_format="%Y-%m-%d").push_application() msg = 'Logging initialized, level: {}, mode: {}'.format( log_level_text, "stdout mode" if not filename else 'file mode: ' + filename ) LogService.get_startup_log().notice(msg)
Example #2
Source File: startup.py From botogram with MIT License | 6 votes |
def configure_logger(): """Configure a logger object""" global _logger_configured # Don't configure the logger multiple times if _logger_configured: return # The StreamHandler will log everything to stdout min_level = 'DEBUG' if 'BOTOGRAM_DEBUG' in os.environ else 'INFO' handler = logbook.StreamHandler(sys.stdout, level=min_level) handler.format_string = '{record.time.hour:0>2}:{record.time.minute:0>2}' \ '.{record.time.second:0>2} - ' \ '{record.level_name:^9} - {record.message}' handler.push_application() # Don't reconfigure the logger, thanks _logger_configured = True
Example #3
Source File: issues.py From PenguinDome with Apache License 2.0 | 6 votes |
def unsnooze_handler(args): if not (args.host or args.issue_name or args.all): sys.exit('If you really want to unsnooze all issues for all hosts,\n' 'you need to specify --all.') hostname = (None if not args.host else args.host[0] if len(args.host) == 1 else {'$in': args.host}) issue_name = (None if not args.issue_name else args.issue_name[0] if len(args.issue_name) == 1 else {'$in': args.issue_name}) ids = unsnooze_issue(hostname, issue_name) if not ids: print('No matching issues.') return with logbook.StreamHandler(sys.stdout, bubble=True): for doc in get_db().issues.find({'_id': {'$in': ids}}): log.info('Unsnoozed {} {} at {}', doc['hostname'], doc['name'], doc['unsnoozed_at'])
Example #4
Source File: gunicorn_conf.py From SnowAlert with Apache License 2.0 | 6 votes |
def post_fork(server, worker): server.log.info('Worker spawned (pid: %s)', worker.pid) logging_rotating_file_handler = logging.handlers.RotatingFileHandler( config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.flask.log'), maxBytes=5 * 1024 * 1024, backupCount=5, ) root_logger = logging.getLogger() root_logger.addHandler(logging_rotating_file_handler) root_logger.setLevel(logging.CRITICAL) logger_setup = logbook.NestedSetup( [ logbook.StreamHandler(sys.stdout, level=logbook.INFO, bubble=True), logbook.RotatingFileHandler( config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.log'), level=logbook.INFO, max_size=5 * 1024 * 1024, bubble=True, ), ] ) logger_setup.push_application()
Example #5
Source File: client_parameters.py From PenguinDome with Apache License 2.0 | 6 votes |
def set_handler(args): old_value = get_client_parameter(args.hostname, args.parameter) try: old = set_client_parameter(args.hostname, args.parameter, args.value) except Exception as e: sys.exit('Failed to set parameter: {}'.format(e)) if not old_value: with logbook.StreamHandler(sys.stdout, bubble=True): log.info('Set parameter {} for host {} to {}', args.parameter, args.hostname, args.value) elif old: with logbook.StreamHandler(sys.stdout, bubble=True): log.info('Changed parameter {} for host {} from {} to {}', args.parameter, args.hostname, old, args.value) else: print('No changes.')
Example #6
Source File: log_service.py From cookiecutter-pyramid-talk-python-starter with MIT License | 6 votes |
def global_init(log_level_text, filename): level = LogService.__get_logbook_logging_level(log_level_text) if not filename: logbook.StreamHandler(sys.stdout, level=level).push_application() else: logbook.TimedRotatingFileHandler( filename, level=level, date_format="%Y-%m-%d").push_application() msg = 'Logging initialized, level: {}, mode: {}'.format( log_level_text, "stdout mode" if not filename else 'file mode: ' + filename ) LogService.get_startup_log().notice(msg)
Example #7
Source File: logging.py From restful-services-in-pyramid with MIT License | 6 votes |
def global_init(logfile): if logfile: logbook.TimedRotatingFileHandler( logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application() else: logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application()
Example #8
Source File: log_service.py From python-for-entrepreneurs-course-demos with MIT License | 6 votes |
def global_init(log_level_text, filename): level = LogService.__get_logbook_logging_level(log_level_text) if not filename: logbook.StreamHandler(sys.stdout, level=level).push_application() else: logbook.TimedRotatingFileHandler( filename, level=level, date_format="%Y-%m-%d").push_application() msg = 'Logging initialized, level: {}, mode: {}'.format( log_level_text, "stdout mode" if not filename else 'file mode: ' + filename ) LogService.get_startup_log().notice(msg)
Example #9
Source File: logging.py From restful-services-in-pyramid with MIT License | 5 votes |
def global_init(logfile): if logfile: logbook.TimedRotatingFileHandler( logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application() else: logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application()
Example #10
Source File: config.py From rep0st with MIT License | 5 votes |
def load(): global is_loaded if not is_loaded: # Patch numpy types into msgpack msgpack_numpy.patch() logbook.StreamHandler(sys.stdout, level=logbook.DEBUG).push_application() logbook.compat.redirect_logging() is_loaded = True
Example #11
Source File: utils.py From regipy with MIT License | 5 votes |
def _get_log_handlers(verbose): return [logbook.StreamHandler(sys.stdout, level=logbook.DEBUG if verbose else logbook.INFO, bubble=True)]
Example #12
Source File: event_log.py From ClusterRunner with Apache License 2.0 | 5 votes |
def _get_event_handler(self): """ Retrieves the correct event handler. Returns a Stream Handler if the event should write to STDOUT, otherwise it will return a ready RotatingFileHandler. Both subclasses inherit from the StreamHandler base class. :return: Event handler :rtype: StreamHandler """ if self.filename.upper() == 'STDOUT': return StreamHandler(sys.stdout) else: fs.create_dir(os.path.dirname(self.filename)) previous_log_file_exists = os.path.exists(self.filename) event_handler = RotatingFileHandler( filename=self.filename, max_size=Configuration['max_eventlog_file_fize'], backup_count=Configuration['max_eventlog_file_backups'] ) if previous_log_file_exists: event_handler.perform_rollover() # force starting a new eventlog file on application startup return event_handler
Example #13
Source File: app.py From SnowAlert with Apache License 2.0 | 5 votes |
def main(): logbook.StreamHandler(sys.stdout).push_application() app.run(host, port)
Example #14
Source File: helpers.py From OdooQuant with GNU General Public License v3.0 | 5 votes |
def get_logger(name, debug=True): logbook.set_datetime_format('local') handler = StreamHandler(sys.stdout) if debug else NullHandler() handler.push_application() return Logger(os.path.basename(name))
Example #15
Source File: logging.py From restful-services-in-pyramid with MIT License | 5 votes |
def global_init(logfile): if logfile: logbook.TimedRotatingFileHandler( logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application() else: logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application()
Example #16
Source File: logging.py From restful-services-in-pyramid with MIT License | 5 votes |
def global_init(logfile): if logfile: logbook.TimedRotatingFileHandler( logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application() else: logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application()
Example #17
Source File: client_parameters.py From PenguinDome with Apache License 2.0 | 5 votes |
def unset_handler(args): try: old = set_client_parameter(args.hostname, args.parameter, None) except Exception as e: sys.exit('Failed to unset parameter: {}'.format(e)) if old: with logbook.StreamHandler(sys.stdout, bubble=True): log.info('Unset parameter {} for host {} (was {})', args.parameter, args.hostname, old) else: print('No changes.')
Example #18
Source File: issues.py From PenguinDome with Apache License 2.0 | 5 votes |
def open_handler(args): with logbook.StreamHandler(sys.stdout, bubble=True): for host in args.host: for issue in args.issue_name: if open_issue(host, issue): log.info('Manually opened {} issue for {}', issue, host) else: print('Open {} issue for {} already exists.'.format( issue, host))
Example #19
Source File: issues.py From PenguinDome with Apache License 2.0 | 5 votes |
def unsuspend_handler(args): matches = unsuspend_host(args.host) if not matches: print('No matching, suspended hosts.') return with logbook.StreamHandler(sys.stdout, bubble=True): for host in matches: log.info('Unsuspended {}', host)
Example #20
Source File: issues.py From PenguinDome with Apache License 2.0 | 5 votes |
def suspend_handler(args): matches = suspend_host(args.host) if not matches: print('No matching, unsuspended hosts.') return with logbook.StreamHandler(sys.stdout, bubble=True): for host in matches: log.info('Suspended {}', host)
Example #21
Source File: issues.py From PenguinDome with Apache License 2.0 | 5 votes |
def snooze_handler(args): if not (args.host or args.issue_name or args.all): sys.exit('If you really want to snooze all issues for all hosts,\n' 'you need to specify --all.') if not (args.days or args.hours): args.days = 1 if args.days: then = now + datetime.timedelta(days=args.days) else: then = now + datetime.timedelta(hours=args.hours) hostname = (None if not args.host else args.host[0] if len(args.host) == 1 else {'$in': args.host}) issue_name = (None if not args.issue_name else args.issue_name[0] if len(args.issue_name) == 1 else {'$in': args.issue_name}) ids = snooze_issue(hostname, issue_name, then) if not ids: print('No matching issues.') return with logbook.StreamHandler(sys.stdout, bubble=True): for doc in get_db().issues.find({'_id': {'$in': ids}}): log.info('Snoozed {} {} until {}', doc['hostname'], doc['name'], then)
Example #22
Source File: renderer.py From btgym with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): self.plug = (np.random.rand(100, 200, 3) * 255).astype(dtype=np.uint8) self.params = {'rendering': 'disabled'} self.render_modes = [] # self.log_level = WARNING # StreamHandler(sys.stdout).push_application() # self.log = Logger('BTgymRenderer', level=self.log_level)
Example #23
Source File: train_dna2vec.py From dna2vec with MIT License | 4 votes |
def main(): argp = configargparse.get_argument_parser() argp.add('-c', is_config_file=True, help='config file path') argp.add_argument('--kmer-fragmenter', help='disjoint or sliding', choices=['disjoint', 'sliding'], default='sliding') argp.add_argument('--vec-dim', help='vector dimension', type=int, default=12) argp.add_argument('--rseed', help='general np.random seed', type=int, default=7) argp.add_argument('--rseed-trainset', help='random seed for generating training data', type=int, default=123) argp.add_argument('--inputs', help='FASTA files', nargs='+', required=True) argp.add_argument('--k-low', help='k-mer start range (inclusive)', type=int, default=5) argp.add_argument('--k-high', help='k-mer end range (inclusive)', type=int, default=5) argp.add_argument('--context', help='half size of context window (the total size is 2*c+1)', type=int, default=4) argp.add_argument('--epochs', help='number of epochs', type=int, default=1) argp.add_argument('--gensim-iters', help="gensim's internal iterations", type=int, default=1) argp.add_argument('--out-dir', help="output directory", default='../dataset/dna2vec/results') argp.add_argument('--debug', help='', action='store_true') args = argp.parse_args() if args.debug: out_dir = '/tmp' log_level = 'DEBUG' else: out_dir = args.out_dir log_level = 'INFO' inputs = [] for s in args.inputs: inputs.extend(list(glob.glob(s))) mbytes = util.estimate_bytes(inputs) // (10 ** 6) out_fileroot = util.get_output_fileroot( out_dir, 'dna2vec', 'k{}to{}-{}d-{}c-{}Mbp-{}'.format( args.k_low, args.k_high, args.vec_dim, args.context, mbytes * args.epochs, # total Mb including epochs args.kmer_fragmenter)) out_txt_filename = '{}.txt'.format(out_fileroot) with open(out_txt_filename, 'w') as summary_fptr: with Tee(summary_fptr): logbook.StreamHandler(sys.stdout, level=log_level).push_application() redirect_logging() run_main(args, inputs, out_fileroot)
Example #24
Source File: renderer.py From btgym with GNU Lesser General Public License v3.0 | 4 votes |
def __init__(self, render_modes, **kwargs): """ Plotting controls, can be passed as kwargs. Args: render_state_as_image=True, render_state_channel=0, render_size_human=(6, 3.5), render_size_state=(7, 3.5), render_size_episode=(12,8), render_dpi=75, render_plotstyle='seaborn', render_cmap='PRGn', render_xlabel='Relative timesteps', render_ylabel='Value', render_title='local step: {}, state observation min: {:.4f}, max: {:.4f}', render_boxtext=dict(fontsize=12, fontweight='bold', color='w', bbox={'facecolor': 'k', 'alpha': 0.3, 'pad': 3}, ) """ # Update parameters with relevant kwargs: for key, value in kwargs.items(): if key in self.params.keys(): self.params[key] = value # Unpack it as attributes: for key, value in self.params.items(): setattr(self, key, value) # Logging: if 'log_level' not in dir(self): self.log_level = WARNING StreamHandler(sys.stdout).push_application() self.log = Logger('BTgymRenderer', level=self.log_level) #from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas #self.FigureCanvas = FigureCanvas self.plt = None # Will set it inside server process when calling initialize_pyplot(). #self.plotter = BTgymPlotter() # Modified bt.Cerebro() plotter, to get episode renderings. # Set empty plugs for each render mode: self.render_modes = render_modes for mode in self.render_modes: self.rgb_dict[mode] = self.rgb_empty()