Use logging module

This commit is contained in:
wheaney 2024-05-22 23:01:46 -07:00
parent a7dd9885e1
commit 9619acdc88
7 changed files with 74 additions and 6 deletions

View File

@ -44,7 +44,7 @@ export const Logger = GObject.registerClass({
constructor(params = {}) { constructor(params = {}) {
super(params); super(params);
this._log_file_dir = `${GLib.get_user_data_dir()}/${LOG_DIR_NAME}/` this._log_file_dir = `${GLib.get_user_state_dir()}/${LOG_DIR_NAME}/`
this._first_log = true; this._first_log = true;
} }

View File

@ -4,6 +4,7 @@
# https://gitlab.gnome.org/GNOME/dconf-editor/-/blob/master/build-aux/start-dconf-editor.sh # https://gitlab.gnome.org/GNOME/dconf-editor/-/blob/master/build-aux/start-dconf-editor.sh
IFS=: read -ra host_data_dirs < <(flatpak-spawn --host sh -c 'echo "$XDG_DATA_DIRS"') IFS=: read -ra host_data_dirs < <(flatpak-spawn --host sh -c 'echo "$XDG_DATA_DIRS"')
IFS=: read -ra HOST_XDG_STATE_HOME < <(flatpak-spawn --host sh -c 'echo "$XDG_STATE_HOME"')
# To avoid potentially muddying up $XDG_DATA_DIRS too much, we link the schema paths # To avoid potentially muddying up $XDG_DATA_DIRS too much, we link the schema paths
# into a temporary directory. # into a temporary directory.
@ -33,5 +34,12 @@ if [[ ! -z "${HOST_XDG_DATA_DIRS}" ]]; then
XDG_DATA_DIRS="${HOST_XDG_DATA_DIRS:1}:${XDG_DATA_DIRS}" XDG_DATA_DIRS="${HOST_XDG_DATA_DIRS:1}:${XDG_DATA_DIRS}"
fi fi
if [[ ! -z "${HOST_XDG_STATE_HOME}" ]]; then
XDG_STATE_HOME="${HOST_XDG_STATE_HOME}"
else
XDG_STATE_HOME="${USER_HOME}/.local/state"
fi
export XDG_DATA_DIRS export XDG_DATA_DIRS
export XDG_STATE_HOME
exec breezydesktop "$@" exec breezydesktop "$@"

View File

@ -32,6 +32,7 @@
], ],
"modules" : [ "modules" : [
"python3-pydbus.json", "python3-pydbus.json",
"python3-requests.json",
{ {
"name": "dconf", "name": "dconf",
"buildsystem": "meson", "buildsystem": "meson",

View File

@ -1,5 +1,5 @@
project('breezydesktop', project('breezydesktop',
version: '0.1.0', version: '0.1.1',
meson_version: '>= 0.62.0', meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', ], default_options: [ 'warning_level=2', 'werror=false', ],
) )

@ -1 +1 @@
Subproject commit 831a31d3b8ac74964be5506b4cd9b81f6755d634 Subproject commit b95aaeeaaaf8ae8e0da25594f332c7a040262aa8

34
ui/python3-requests.json Normal file
View File

@ -0,0 +1,34 @@
{
"name": "python3-requests",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"requests\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ba/06/a07f096c664aeb9f01624f858c3add0a4e913d6c96257acb4fce61e7de14/certifi-2024.2.2-py3-none-any.whl",
"sha256": "dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/63/09/c1bc53dab74b1816a00d8d030de5bf98f724c52c1635e07681d312f20be8/charset-normalizer-3.3.2.tar.gz",
"sha256": "f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/e5/3e/741d8c82801c347547f8a2a06aa57dbb1992be9e948df2ea0eda2c8b79e8/idna-3.7-py3-none-any.whl",
"sha256": "82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/c3/20/748e38b466e0819491f0ce6e90ebe4184966ee304fe483e2c414b0f4ef07/requests-2.32.2-py3-none-any.whl",
"sha256": "fc06670dd0ed212426dfeb94fc1b983d917c4f9847c863f313c9dfaaffb7c23c"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/a2/73/a68704750a7679d0b6d3ad7aa8d4da8e14e151ae82e6fee774e6e0d05ec8/urllib3-2.2.1-py3-none-any.whl",
"sha256": "450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"
}
]
}

View File

@ -17,17 +17,43 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
import sys import sys
import gi import gi
from logging.handlers import TimedRotatingFileHandler
gi.require_version('Gtk', '4.0') gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1') gi.require_version('Adw', '1')
gi.require_version('Gio', '2.0') gi.require_version('Gio', '2.0')
gi.require_version('GLib', '2.0')
from gi.repository import Adw, Gtk, Gio from gi.repository import Adw, Gtk, Gio, GLib
from .licensedialog import LicenseDialog from .licensedialog import LicenseDialog
from .statemanager import StateManager from .statemanager import StateManager
from .window import BreezydesktopWindow from .window import BreezydesktopWindow
from .xrdriveripc import XRDriverIPC
state_dir = os.path.expanduser("~/.local/state")
log_dir = os.path.join(state_dir, 'breezy_gnome/logs/ui')
os.makedirs(log_dir, exist_ok=True)
logger = logging.getLogger('breezy_ui')
logger.setLevel(logging.INFO)
logname = os.path.join(log_dir, "breezy_desktop.log")
handler = TimedRotatingFileHandler(logname, when="midnight", backupCount=30)
handler.suffix = "%Y%m%d"
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
def excepthook(exc_type, exc_value, exc_traceback):
logger.error('Unhandled exception', exc_info=(exc_type, exc_value, exc_traceback))
sys.excepthook = excepthook
XRDriverIPC.set_instance(XRDriverIPC(logger))
class BreezydesktopApplication(Adw.Application): class BreezydesktopApplication(Adw.Application):
"""The main application singleton class.""" """The main application singleton class."""
@ -58,7 +84,7 @@ class BreezydesktopApplication(Adw.Application):
modal=True, modal=True,
program_name='Breezy Desktop', program_name='Breezy Desktop',
logo_icon_name='com.xronlinux.BreezyDesktop', logo_icon_name='com.xronlinux.BreezyDesktop',
version='0.1.0', version='0.1.1',
authors=['Wayne Heaney'], authors=['Wayne Heaney'],
copyright='© 2024 Wayne Heaney') copyright='© 2024 Wayne Heaney')
about.present() about.present()
@ -93,6 +119,5 @@ class BreezydesktopApplication(Adw.Application):
def main(version): def main(version):
"""The application's entry point."""
app = BreezydesktopApplication() app = BreezydesktopApplication()
return app.run(sys.argv) return app.run(sys.argv)