# HG changeset patch # User sqwishy # Date 1521696072 25200 # Wed Mar 21 22:21:12 2018 -0700 # Node ID 7a40ffbfad168c5865de44ec093d25e192ad87e7 # Parent 7dcff60e033532e83b0fd8d89cc812a6ddbdaf88 Logging to a file when built and frozen diff --git a/winrustler.spec b/winrustler.spec --- a/winrustler.spec +++ b/winrustler.spec @@ -26,4 +26,4 @@ strip=False, upx=True, runtime_tmpdir=None, - console=True , icon='winrustler.ico') + console=False , icon='winrustler.ico') diff --git a/winrustler/ui/__main__.py b/winrustler/ui/__main__.py --- a/winrustler/ui/__main__.py +++ b/winrustler/ui/__main__.py @@ -1,5 +1,7 @@ +import logging +import pathlib +import platform import sys -import logging from PyQt5.QtWidgets import qApp, QMenu @@ -9,17 +11,28 @@ logger = logging.getLogger(__name__) +is_frozen = getattr(sys, 'frozen', False) +if platform.system() == 'Windows': + runtime_path = pathlib.Path.home() / "AppData" / "Roaming" / "winrustler" +else: + runtime_path = None def main(): import argparse parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-v', help='Verbosity, more of these increases logging.', action='count', default=0) - parser.add_argument('--show', help='Display rustler window on startu..', action='store_true') + parser.add_argument('--show', help='Display rustler window on startup.', action='store_true') parser.add_argument('qt_args', nargs='*') args = parser.parse_args() log_level = {0: logging.WARNING, 1: logging.INFO}.get(args.v, logging.DEBUG) logging.basicConfig(level=log_level) + if is_frozen and runtime_path is not None: + runtime_path.mkdir(exist_ok=True) + logfile = str(runtime_path / 'logging.txt') + logger.info("Logging to %s", logfile) + handler = logging.FileHandler(logfile) + logging.getLogger().addHandler(handler) logger.info("Logging level set to %s.", log_level) if not RustlerTray.isSystemTrayAvailable():