def __init__(self, logger, level, name, data=None, reraise=True, parent=None, frame=None): self.action_id = next(_ACT_ID_ITER) self.logger = logger self.level = get_level(level) self.name = name self.data_map = data or {} self._reraise = reraise if frame is None: frame = sys._getframe(1) self.callpoint = Callpoint.from_frame(frame) self.begin_event = None self.end_event = None # these can go internal and be lazily created through properties self.warn_events = [] self.exc_events = [] if parent: self.parent_action = parent else: self.parent_action = logger.context.get_active_parent(logger, self) return
def __init__(self, logger, level, name, data=None, reraise=True, parent=None, frame=None): self.action_id = next(_ACT_ID_ITER) self.logger = logger self.level = get_level(level) try: self.name = unicode(name) except Exception: self.name = repr(name) self.data_map = data or {} self._reraise = reraise if frame is None: frame = sys._getframe(1) self.callpoint = Callpoint.from_frame(frame) self.begin_event = None self.end_event = None if parent: self.parent_action = parent else: self.parent_action = logger.context.get_active_parent(logger, self) return
def __init__(self, logger, level, name, data=None, reraise=True, parent=None, frame=None): self.action_id = next(_ACT_ID_ITER) self.logger = logger self.level = get_level(level) try: self.name = unicode(name) except Exception: self.name = repr(name) self.data_map = data or {} self._reraise = reraise if frame is None: frame = sys._getframe(1) self.callpoint = Callpoint.from_frame(frame) self.begin_event = None self.end_event = None if parent: self.parent_action = parent else: self.parent_action = logger.context.get_active_parent(logger, self) return
def __init__(self, name, **kwargs): enable_begin = kwargs.pop("enable_begin", True) out_min_level = get_level(kwargs.pop("min_level", DEBUG)) if kwargs: raise TypeError("unexpected keyword arguments: %r" % kwargs) # exc_filter = debug_callable(ThresholdFilter(exception=0)) exc_filter = ThresholdFilter(exception=DEBUG) exc_formatter = Formatter("!! {exc_type}: {exc_tb_str}") exc_emitter = StreamEmitter("stderr") exc_sink = SensibleSink(exc_formatter, exc_emitter, [exc_filter]) event_levels = { "success": out_min_level, "failure": get_prev_level(out_min_level), "exception": get_prev_level(out_min_level, 2), } out_filter = ThresholdFilter(**event_levels) # TODO: warn_char (requires len on FormatField) out_formatter = Formatter(OUT_TMPL) out_emitter = StreamEmitter("stdout") out_sink = SensibleSink(out_formatter, out_emitter, [out_filter]) self.quantile_sink = q_sink = QuantileSink() sinks = [q_sink, exc_sink, out_sink] if enable_begin: beg_filter = ThresholdFilter(begin=DEBUG) beg_formatter = Formatter(BEG_TMPL) beg_sink = SensibleSink(beg_formatter, out_emitter, filters=[beg_filter], on="begin") sinks.append(beg_sink) super(BarnsworthLogger, self).__init__(name, sinks)
def _get_syslog_priority(self, event_name, action): level = get_level(action.level) if event_name == 'warn': status = 'warn' elif event_name == 'begin': status = 'begin' else: status = action.status return self.priority_map[level][status]
def __init__(self, base=None, **kw): # TODO: on-bind lookup behaviors? base = get_level(base or MAX_LEVEL) self.begin_level = get_level(kw.pop('begin', base) or MAX_LEVEL) self.success_level = get_level(kw.pop('success', base) or MAX_LEVEL) self.failure_level = get_level(kw.pop('failure', base) or MAX_LEVEL) self.exception_level = get_level( kw.pop('exception', base) or MAX_LEVEL) self.warn_level = get_level(kw.pop('warn', base) or MAX_LEVEL) self.block_comments = kw.pop('block_comments', False) self.verbose_check = kw.pop('verbose_check', None) if not self.verbose_check: verbose_flag = kw.pop('verbose_flag', 'verbose') self.verbose_check = lambda e: e.action.data_map.get(verbose_flag) if kw: raise TypeError('got unexpected keyword arguments: %r' % kw)
def __init__(self, base=None, **kw): # TODO: on-bind lookup behaviors? base = get_level(base or MAX_LEVEL) self.begin_level = get_level(kw.pop('begin', base) or MAX_LEVEL) self.success_level = get_level(kw.pop('success', base) or MAX_LEVEL) self.failure_level = get_level(kw.pop('failure', base) or MAX_LEVEL) self.exception_level = get_level(kw.pop('exception', base) or MAX_LEVEL) self.warn_level = get_level(kw.pop('warn', base) or MAX_LEVEL) self.block_comments = kw.pop('block_comments', False) self.verbose_check = kw.pop('verbose_check', None) if not self.verbose_check: verbose_flag = kw.pop('verbose_flag', 'verbose') self.verbose_check = lambda e: e.action.data_map.get(verbose_flag) if kw: raise TypeError('got unexpected keyword arguments: %r' % kw)
def test_level_getting(): assert get_level('debug') == DEBUG assert get_level('CRITICAL') == CRITICAL assert get_level(int(INFO._value)) == INFO assert get_level(DEFAULT_LEVEL) == DEFAULT_LEVEL