diff --git a/bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_debug.py b/bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_debug.py index 3ac86264..374ef82d 100644 --- a/bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_debug.py +++ b/bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_debug.py @@ -20,25 +20,18 @@ if BUBBLE_PORT is None: BUBBLE_LOG = '/var/log/bubble/mitmproxy_bubble.log' BUBBLE_LOG_LEVEL_FILE = '/home/mitmproxy/bubble_log_level.txt' BUBBLE_LOG_LEVEL_ENV_VAR = 'BUBBLE_LOG_LEVEL' -DEFAULT_BUBBLE_LOG_LEVEL = 'WARNING' +DEFAULT_BUBBLE_LOG_LEVEL = 'INFO' BUBBLE_LOG_LEVEL = None -try: - BUBBLE_LOG_LEVEL = Path(BUBBLE_LOG_LEVEL_FILE).read_text().strip() -except IOError: - print('error reading log level from '+BUBBLE_LOG_LEVEL_FILE+', checking env var '+BUBBLE_LOG_LEVEL_ENV_VAR, file=sys.stderr, flush=True) - BUBBLE_LOG_LEVEL = os.getenv(BUBBLE_LOG_LEVEL_ENV_VAR, DEFAULT_BUBBLE_LOG_LEVEL) -BUBBLE_NUMERIC_LOG_LEVEL = getattr(logging, BUBBLE_LOG_LEVEL.upper(), None) -if not isinstance(BUBBLE_NUMERIC_LOG_LEVEL, int): - print('Invalid log level: ' + BUBBLE_LOG_LEVEL + ' - using default '+DEFAULT_BUBBLE_LOG_LEVEL, file=sys.stderr, flush=True) - BUBBLE_NUMERIC_LOG_LEVEL = getattr(logging, DEFAULT_BUBBLE_LOG_LEVEL.upper(), None) -logging.basicConfig(format='[mitm'+BUBBLE_PORT+'] %(asctime)s - [%(module)s:%(lineno)d] - %(levelname)s: %(message)s', filename=BUBBLE_LOG, level=BUBBLE_NUMERIC_LOG_LEVEL) -bubble_log = logging.getLogger(__name__) +def get_stack(e=None): + if e is None: + e = ValueError() + return "".join(traceback.TracebackException.from_exception(e).format()) # Allow SIGUSR1 to print stack traces to stderr -def dumpstacks(signal, frame): +def dump_stacks(signal, frame): id2name = dict([(th.ident, th.name) for th in threading.enumerate()]) code = [] for threadId, stack in sys._current_frames().items(): @@ -50,7 +43,21 @@ def dumpstacks(signal, frame): print("\n------------------------------------- stack traces ------------------------------"+"\n".join(code), file=sys.stderr, flush=True) -signal.signal(signal.SIGUSR1, dumpstacks) +signal.signal(signal.SIGUSR1, dump_stacks) + +try: + BUBBLE_LOG_LEVEL = Path(BUBBLE_LOG_LEVEL_FILE).read_text().strip() +except IOError: + print('error reading log level from '+BUBBLE_LOG_LEVEL_FILE+', checking env var '+BUBBLE_LOG_LEVEL_ENV_VAR, file=sys.stderr, flush=True) + BUBBLE_LOG_LEVEL = os.getenv(BUBBLE_LOG_LEVEL_ENV_VAR, DEFAULT_BUBBLE_LOG_LEVEL) + +BUBBLE_NUMERIC_LOG_LEVEL = getattr(logging, BUBBLE_LOG_LEVEL.upper(), None) +if not isinstance(BUBBLE_NUMERIC_LOG_LEVEL, int): + print('Invalid log level: ' + BUBBLE_LOG_LEVEL + ' - using default '+DEFAULT_BUBBLE_LOG_LEVEL, file=sys.stderr, flush=True) + BUBBLE_NUMERIC_LOG_LEVEL = getattr(logging, DEFAULT_BUBBLE_LOG_LEVEL.upper(), None) +logging.basicConfig(format='[mitm'+BUBBLE_PORT+'] %(asctime)s - [%(module)s:%(lineno)d] - %(levelname)s: %(message)s', filename=BUBBLE_LOG, level=BUBBLE_NUMERIC_LOG_LEVEL) + +bubble_log = logging.getLogger(__name__) if bubble_log.isEnabledFor(INFO): bubble_log.info('debug module initialized, default log level = '+logging.getLevelName(BUBBLE_NUMERIC_LOG_LEVEL)) diff --git a/bubble-server/src/main/resources/packer/roles/mitmproxy/files/run_mitm.sh b/bubble-server/src/main/resources/packer/roles/mitmproxy/files/run_mitm.sh index f2eae5cb..0bcd219a 100644 --- a/bubble-server/src/main/resources/packer/roles/mitmproxy/files/run_mitm.sh +++ b/bubble-server/src/main/resources/packer/roles/mitmproxy/files/run_mitm.sh @@ -25,7 +25,6 @@ BUBBLE_PORT=${PORT} mitmdump \ --set flow_detail=0 \ --set stream_large_bodies=1 \ --set keep_host_header \ - -s ./bubble_debug.py \ -s ./bubble_conn_check.py \ -s ./bubble_request.py \ -s ./bubble_modify.py \