Automatically set up basic logging for the desktop app.

master
Pacman Ghost 2 years ago
parent 499e5645bc
commit 0b720dc8bc
  1. 11
      vasl_templates/main.py
  2. 10
      vasl_templates/main_window.py
  3. 13
      vasl_templates/utils.py
  4. BIN
      vasl_templates/webapp/static/images/menu/log.png
  5. 4
      vasl_templates/webapp/user_profile.py

@ -102,6 +102,17 @@ def _do_main( template_pack, default_scenario, remote_debugging, debug ): #pylin
from vasl_templates.webapp import globvars, load_debug_config
from vasl_templates.webapp import main as webapp_main, snippets as webapp_snippets
# initialize logging
# NOTE: We set up basic logging for people using the desktop app (if they are running from source,
# or using Docker, there is an expectation they can do this themselves). If logging has already
# been set up, this config is in *addition* to what's already been configured.
handler = logging.FileHandler( globvars.user_profile.default_log_fname, mode="w" )
handler.setLevel( logging.WARNING )
handler.setFormatter(
logging.Formatter( "%(asctime)s | %(message)s" )
)
logging.getLogger().addHandler( handler )
# configure the default template pack
if template_pack:
if template_pack.lower().endswith( ".zip" ):

@ -14,9 +14,10 @@ from PyQt5.QtGui import QDesktopServices, QIcon
from PyQt5.QtCore import Qt, QUrl, QMargins, pyqtSlot, QVariant
from vasl_templates.webapp.config.constants import APP_NAME, APP_VERSION, IS_FROZEN
from vasl_templates.webapp import globvars
from vasl_templates.main import app_settings
from vasl_templates.web_channel import WebChannelHandler
from vasl_templates.utils import catch_exceptions
from vasl_templates.utils import catch_exceptions, launch_file
_CONSOLE_SOURCE_REGEX = re.compile( r"^http://.+?/static/(.*)$" )
@ -44,7 +45,7 @@ class AppWebPage( QWebEnginePage ):
mo = _CONSOLE_SOURCE_REGEX.search( source_id )
source = mo.group(1) if mo else source_id
logger = logging.getLogger( "javascript" )
logger.info( "%s:%d - %s", source, line_no, msg )
logger.warning( "%s:%d - %s", source, line_no, msg )
# ---------------------------------------------------------------------
@ -80,6 +81,7 @@ class MainWindow( QWidget ):
action.triggered.connect( handler )
file_menu.addAction( action )
add_action( "&Settings", "settings.png", self.on_settings )
add_action( "&Log file", "log.png", self.on_log_file )
add_action( "&About", "info.png", self.on_about )
file_menu.addSeparator()
add_action( "E&xit", "exit.png", self.on_exit )
@ -219,6 +221,10 @@ class MainWindow( QWidget ):
dlg = ServerSettingsDialog( self )
dlg.exec_()
def on_log_file( self ):
"""Menu action handler."""
launch_file( globvars.user_profile.default_log_fname )
def on_about( self ):
"""Menu action handler."""
from vasl_templates.about import AboutDialog #pylint: disable=cyclic-import

@ -1,6 +1,8 @@
""" Miscellaneous utilities. """
import os
import platform
import subprocess
import functools
import logging
import traceback
@ -78,3 +80,14 @@ def show_msg_store( msg_store ):
for msg_type in ("error","warning"):
for msg in msg_store.get_msgs( msg_type ):
MainWindow.showErrorMsg( msg )
# ---------------------------------------------------------------------
def launch_file( fname ):
"""Launch the specified file."""
if platform.system() == "Windows":
os.startfile( fname ) #pylint: disable=no-member
elif platform.system() == "Darwin":
subprocess.call( ("open", fname) )
else:
subprocess.call( ("xdg-open", fname) )

Binary file not shown.

After

Width:  |  Height:  |  Size: 762 B

@ -40,6 +40,8 @@ class UserProfile:
# configure the location of the log files
self.logs_dname = "/tmp" if is_container \
else self._check_dir( appdirs.user_log_dir( _APP_NAME, _APP_AUTHOR ) )
if is_desktop_app:
self.default_log_fname = os.path.join( self.logs_dname, "app.log" )
self.webdriver_log_fname = app_config.get( "WEBDRIVER_LOG",
os.path.join( self.logs_dname, "webdriver.log" )
)
@ -61,6 +63,8 @@ class UserProfile:
_logger.info( "- local data = %s", self.local_data_dname )
_logger.debug( " - Flask lock file = %s", self.flask_lock_fname )
_logger.info( "- logs = %s", self.logs_dname )
if is_desktop_app:
_logger.debug( "- app = %s", self.default_log_fname )
_logger.debug( " - webdriver = %s", self.webdriver_log_fname )
_logger.info( "- cache = %s", self.cache_dname )
for key, val in self.downloaded_files.items():

Loading…
Cancel
Save