diff options
author | Ivan Alejandro <ivanalejandro0@gmail.com> | 2015-10-06 12:43:13 -0300 |
---|---|---|
committer | Ivan Alejandro <ivanalejandro0@gmail.com> | 2015-10-06 15:54:59 -0300 |
commit | a1d6d06ec05ad3e2fb8f8b43fb693d2e1b4c75be (patch) | |
tree | feb5280cf99493842d4163cc22e17766066c004a | |
parent | 5518564ef8e054dbf15cd022ca01ccc656c89e5b (diff) |
[bug] store logs in the right place
Load flags before creating logger so the logs path considers the
standalone flag.
Move the log file path definition to the function, otherwise it will
calculated during import and (most likely) before defining the
flags.STANDALONE value.
Create logger inside `run_frontend` right after knowing if we are
standalone or not.
- Resolves: #7512
-rw-r--r-- | src/leap/bitmask/backend_app.py | 6 | ||||
-rw-r--r-- | src/leap/bitmask/frontend_app.py | 9 | ||||
-rw-r--r-- | src/leap/bitmask/logs/utils.py | 15 |
3 files changed, 15 insertions, 15 deletions
diff --git a/src/leap/bitmask/backend_app.py b/src/leap/bitmask/backend_app.py index 1900c08f..fb1f4400 100644 --- a/src/leap/bitmask/backend_app.py +++ b/src/leap/bitmask/backend_app.py @@ -67,14 +67,14 @@ def run_backend(bypass_checks=False, flags_dict=None, frontend_pid=None): observer = PythonLoggingObserver() observer.start() + if flags_dict is not None: + dict_to_flags(flags_dict) + # NOTE: this needs to be used here, within the call since this function is # executed in a different process and it seems that the process/thread # identification isn't working 100% logger = get_logger() # noqa - if flags_dict is not None: - dict_to_flags(flags_dict) - # The backend is the one who always creates the certificates. Either if it # is run separately or in a process in the same app as the frontend. if flags.ZMQ_HAS_CURVE: diff --git a/src/leap/bitmask/frontend_app.py b/src/leap/bitmask/frontend_app.py index fed24cfa..60391f50 100644 --- a/src/leap/bitmask/frontend_app.py +++ b/src/leap/bitmask/frontend_app.py @@ -31,10 +31,8 @@ from leap.bitmask.gui.mainwindow import MainWindow from leap.bitmask.logs.utils import get_logger from leap.bitmask.util import dict_to_flags -logger = get_logger() - -def signal_handler(window, pid, signum, frame): +def signal_handler(window, pid, logger, signum, frame): """ Signal handler that quits the running app cleanly. @@ -42,6 +40,8 @@ def signal_handler(window, pid, signum, frame): :type window: MainWindow :param pid: process id of the main process. :type pid: int + :param logger: the logger object to use for logging + :type logger: logbook.Logger :param signum: number of the signal received (e.g. SIGINT -> 2) :type signum: int :param frame: current stack frame @@ -70,6 +70,7 @@ def run_frontend(options, flags_dict, backend_pid=None): :type flags_dict: dict """ dict_to_flags(flags_dict) + logger = get_logger() start_hidden = options["start_hidden"] @@ -120,7 +121,7 @@ def run_frontend(options, flags_dict, backend_pid=None): window = MainWindow(start_hidden=start_hidden, backend_pid=backend_pid) my_pid = os.getpid() - sig_handler = partial(signal_handler, window, my_pid) + sig_handler = partial(signal_handler, window, my_pid, logger) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) diff --git a/src/leap/bitmask/logs/utils.py b/src/leap/bitmask/logs/utils.py index e38839c7..f54e86ff 100644 --- a/src/leap/bitmask/logs/utils.py +++ b/src/leap/bitmask/logs/utils.py @@ -37,19 +37,18 @@ from logbook.more import ColorizedStderrHandler from logbook.queues import ZeroMQSubscriber -# NOTE: make sure that the folder exists, the logger is created before saving -# settings on the first run. -_base = os.path.join(get_path_prefix(), "leap") -mkdir_p(_base) -BITMASK_LOG_FILE = os.path.join(_base, 'bitmask.log') - - def get_logger(perform_rollover=False): """ Push to the app stack the needed handlers and return a Logger object. :rtype: logbook.Logger """ + # NOTE: make sure that the folder exists, the logger is created before + # saving settings on the first run. + _base = os.path.join(get_path_prefix(), "leap") + mkdir_p(_base) + bitmask_log_file = os.path.join(_base, 'bitmask.log') + level = logbook.WARNING if flags.DEBUG: level = logbook.NOTSET @@ -65,7 +64,7 @@ def get_logger(perform_rollover=False): zmq_handler.push_application() file_handler = logbook.RotatingFileHandler( - BITMASK_LOG_FILE, format_string=LOG_FORMAT, bubble=True, + bitmask_log_file, format_string=LOG_FORMAT, bubble=True, filter=silencer.filter, max_size=sys.maxint) if perform_rollover: |