def sig_add_log(self, sender, e, level): if log.log_tier(self.options.verbosity) < log.log_tier(level): return if level in ("error", "warn"): signals.status_message.send( message = "{}: {}".format(level.title(), e) )
def __call__(self, *args, level: LogTierOrder = 'info') -> None: if log_tier(ctx.options.bulog_verbosity) < log_tier(level): return secho( ' '.join(str(arg) for arg in args), fg=dict(error="red", warn="yellow", alert="magenta").get(level), dim=(level == "debug"), err=(level == "error"), )
def add_log(self, e): if log.log_tier(ctx.options.termlog_verbosity) >= log.log_tier( e.level): click.secho(e.msg, file=self.outfile, fg=dict(error="red", warn="yellow", alert="magenta").get(e.level), dim=(e.level == "debug"), err=(e.level == "error"))
def sig_add_log(self, event_store, entry: log.LogEntry): if log.log_tier( self.options.console_eventlog_verbosity) < log.log_tier( entry.level): return if entry.level in ("error", "warn", "alert"): signals.status_message.send(message=(entry.level, "{}: {}".format( entry.level.title(), str(entry.msg).lstrip())), expire=5)
def add_event(self, event_store, entry: log.LogEntry): if log.log_tier(self.master.options.console_eventlog_verbosity) < log.log_tier(entry.level): return txt = "%s: %s" % (entry.level, str(entry.msg)) if entry.level in ("error", "warn", "alert"): e = urwid.Text((entry.level, txt)) else: e = urwid.Text(txt) self.walker.append(e) if self.master.options.console_focus_follow: self.walker.set_focus(len(self.walker) - 1)
def sig_add_log(self, event_store, entry: log.LogEntry): if log.log_tier(self.options.verbosity) < log.log_tier(entry.level): return if entry.level in ("error", "warn"): if self.first_tick: self.start_err = entry else: signals.status_message.send( message=(entry.level, "{}: {}".format(entry.level.title(), entry.msg)), expire=5 )
def sig_add_log(self, event_store, entry: log.LogEntry): if log.log_tier(self.options.console_eventlog_verbosity) < log.log_tier(entry.level): return if entry.level in ("error", "warn", "alert"): signals.status_message.send( message = ( entry.level, "{}: {}".format(entry.level.title(), str(entry.msg).lstrip()) ), expire=5 )
def add_event(self, event_store, entry: log.LogEntry): if log.log_tier(self.master.options.verbosity) < log.log_tier(entry.level): return txt = "%s: %s" % (entry.level, str(entry.msg)) if entry.level in ("error", "warn"): e = urwid.Text((entry.level, txt)) else: e = urwid.Text(txt) self.walker.append(e) if self.master.options.console_focus_follow: self.walker.set_focus(len(self.walker) - 1)
def log(self, e): if log.log_tier(e.level) == log.log_tier("error"): outfile = self.outfile or sys.stderr else: outfile = self.outfile or sys.stdout if self.options.verbosity >= log.log_tier(e.level): click.secho(e.msg, file=outfile, fg=dict(error="red", warn="yellow").get(e.level), dim=(e.level == "debug"), err=(e.level == "error"))
def sig_add_log(self, event_store, entry: log.LogEntry): if log.log_tier(self.options.verbosity) < log.log_tier(entry.level): return if entry.level in ("error", "warn", "alert"): if self.first_tick: self.start_err = entry else: signals.status_message.send(message=(entry.level, "{}: {}".format( entry.level.title(), entry.msg)), expire=5)
def sig_add_log(self, sender, e, level): if log.log_tier(ctx.options.verbosity) < log.log_tier(level): return txt = "%s: %s" % (level, str(e)) if level in ("error", "warn"): e = urwid.Text((level, txt)) else: e = urwid.Text(txt) self.walker.append(e) if len(self.walker) > EVENTLOG_SIZE: self.walker.pop(0) if self.master.options.console_focus_follow: self.walker.set_focus(len(self.walker) - 1)
def log(self, e): if log.log_tier(e.level) == log.log_tier("error"): outfile = self.outfile or realstderr else: outfile = self.outfile or realstdout if log.log_tier(ctx.options.verbosity) >= log.log_tier(e.level): click.secho( e.msg, file=outfile, fg=dict(error="red", warn="yellow").get(e.level), dim=(e.level == "debug"), err=(e.level == "error") )
def log(self, e): if self.options.verbosity >= log.log_tier(e.level): click.secho( e.msg, file=self.options.tfile, fg=dict(error="red", warn="yellow").get(e.level), dim=(e.level == "debug"), err=(e.level == "error") )
def add_log(self, e: log.LogEntry): if log.log_tier(ctx.options.termlog_verbosity) >= log.log_tier( e.level): if e.level == "error": f = self.err_file has_vt_codes = self.err_has_vt_codes else: f = self.out_file has_vt_codes = self.out_has_vt_codes msg = e.msg if has_vt_codes: msg = miniclick.style( e.msg, fg=LOG_COLORS.get(e.level), dim=(e.level == "debug"), ) print(msg, file=f)
def run(master_cls: typing.Type[master.Master], make_parser: typing.Callable[[options.Options], argparse.ArgumentParser], arguments: typing.Sequence[str], extra=typing.Callable[[typing.Any], dict]): # pragma: no cover """ extra: Extra argument processing callable which returns a dict of options. """ debug.register_info_dumpers() opts = options.Options() master = master_cls(opts) parser = make_parser(opts) args = parser.parse_args(arguments) try: unknown = optmanager.load_paths(opts, args.conf) pconf = process_options(parser, opts, args) server = None # type: typing.Any if pconf.options.server: try: server = proxy.server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1) else: server = proxy.server.DummyServer(pconf) master.server = server master.addons.trigger("configure", opts.keys()) master.addons.trigger("tick") remaining = opts.update_known(**unknown) if remaining and log.log_tier(opts.verbosity) > 1: print("Ignored options: %s" % remaining) if args.options: print(optmanager.dump_defaults(opts)) sys.exit(0) if args.commands: master.commands.dump() sys.exit(0) opts.set(*args.setoptions) if extra: opts.update(**extra(args)) def cleankill(*args, **kwargs): master.shutdown() signal.signal(signal.SIGTERM, cleankill) master.run() except exceptions.OptionsError as e: print("%s: %s" % (sys.argv[0], e), file=sys.stderr) sys.exit(1) except (KeyboardInterrupt, RuntimeError) as e: pass return master
def sig_add_log(self, sender, e, level): if self.options.verbosity < log.log_tier(level): return if level in ("error", "warn"): signals.status_message.send( message="{}: {}".format(level.title(), e)) e = urwid.Text((level, str(e))) else: e = urwid.Text(str(e)) self.logbuffer.append(e) if len(self.logbuffer) > EVENTLOG_SIZE: self.logbuffer.pop(0) self.logbuffer.set_focus(len(self.logbuffer) - 1)
def sig_add_log(self, sender, e, level): if self.options.verbosity < log.log_tier(level): return if level in ("error", "warn"): signals.status_message.send( message = "{}: {}".format(level.title(), e) ) e = urwid.Text((level, str(e))) else: e = urwid.Text(str(e)) self.logbuffer.append(e) if len(self.logbuffer) > EVENTLOG_SIZE: self.logbuffer.pop(0) self.logbuffer.set_focus(len(self.logbuffer) - 1)
def run(master_cls: typing.Type[master.Master], make_parser: typing.Callable[[options.Options], argparse.ArgumentParser], arguments: typing.Sequence[str], extra: typing.Callable[[typing.Any], dict] = None): # pragma: no cover """ extra: Extra argument processing callable which returns a dict of options. """ debug.register_info_dumpers() opts = options.Options() master = master_cls(opts) parser = make_parser(opts) # To make migration from 2.x to 3.0 bearable. if "-R" in sys.argv and sys.argv[sys.argv.index("-R") + 1].startswith("http"): print( "-R is used for specifying replacements.\n" "To use mitmproxy in reverse mode please use --mode reverse:SPEC instead" ) try: args = parser.parse_args(arguments) except SystemExit: arg_check.check() sys.exit(1) try: unknown = optmanager.load_paths(opts, args.conf) pconf = process_options(parser, opts, args) server = None # type: typing.Any if pconf.options.server: try: server = proxy.server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1) else: server = proxy.server.DummyServer(pconf) master.server = server master.addons.trigger("configure", opts.keys()) master.addons.trigger("tick") remaining = opts.update_known(**unknown) if remaining and log.log_tier(opts.verbosity) > 1: print("Ignored options: %s" % remaining) if args.options: print(optmanager.dump_defaults(opts)) sys.exit(0) if args.commands: master.commands.dump() sys.exit(0) opts.set(*args.setoptions) if extra: opts.update(**extra(args)) def cleankill(*args, **kwargs): master.shutdown() signal.signal(signal.SIGTERM, cleankill) master.run() except exceptions.OptionsError as e: print("%s: %s" % (sys.argv[0], e), file=sys.stderr) sys.exit(1) except (KeyboardInterrupt, RuntimeError) as e: pass return master
def run( master_cls: typing.Type[master.Master], make_parser: typing.Callable[[options.Options], argparse.ArgumentParser], arguments: typing.Sequence[str], extra: typing.Callable[[typing.Any], dict] = None ): # pragma: no cover """ extra: Extra argument processing callable which returns a dict of options. """ debug.register_info_dumpers() opts = options.Options() master = master_cls(opts) parser = make_parser(opts) # To make migration from 2.x to 3.0 bearable. if "-R" in sys.argv and sys.argv[sys.argv.index("-R") + 1].startswith("http"): print("-R is used for specifying replacements.\n" "To use mitmproxy in reverse mode please use --mode reverse:SPEC instead") try: args = parser.parse_args(arguments) except SystemExit: arg_check.check() sys.exit(1) try: unknown = optmanager.load_paths(opts, args.conf) pconf = process_options(parser, opts, args) server = None # type: typing.Any if pconf.options.server: try: server = proxy.server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1) else: server = proxy.server.DummyServer(pconf) master.server = server master.addons.trigger("configure", opts.keys()) master.addons.trigger("tick") remaining = opts.update_known(**unknown) if remaining and log.log_tier(opts.verbosity) > 1: print("Ignored options: %s" % remaining) if args.options: print(optmanager.dump_defaults(opts)) sys.exit(0) if args.commands: master.commands.dump() sys.exit(0) opts.set(*args.setoptions) if extra: opts.update(**extra(args)) def cleankill(*args, **kwargs): master.shutdown() signal.signal(signal.SIGTERM, cleankill) master.run() except exceptions.OptionsError as e: print("%s: %s" % (sys.argv[0], e), file=sys.stderr) sys.exit(1) except (KeyboardInterrupt, RuntimeError) as e: pass return master