Windows: Add debug logging switch in preferences

If debug logging is enabled verbose output is redirected to a file
in the user dir
This commit is contained in:
Philipp Hörist 2018-09-23 14:25:02 +02:00
parent 3bdcd53ff5
commit 5db0178a15
5 changed files with 63 additions and 1 deletions

View File

@ -34,6 +34,8 @@
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import sys
from datetime import datetime
from pathlib import Path
from urllib.parse import unquote
from gi.repository import GLib, Gio, Gtk
@ -291,7 +293,14 @@ class GajimApplication(Gtk.Application):
configpaths.set_config_root(path)
configpaths.init()
logging_helpers.init()
if app.get_win_debug_mode():
# Redirect has to happen before logging init
self._redirect_output()
logging_helpers.init()
logging_helpers.set_verbose()
else:
logging_helpers.init()
if options.contains('quiet'):
logging_helpers.set_quiet()
@ -318,6 +327,14 @@ class GajimApplication(Gtk.Application):
warnings.showwarning = warn_with_traceback
warnings.filterwarnings(action="always")
@staticmethod
def _redirect_output():
debug_folder = Path(configpaths.get('DEBUG'))
date = datetime.today().strftime('%Y-%m-%d')
filename = '%s-debug.log' % date
fd = open(debug_folder / filename, 'a')
sys.stderr = sys.stdout = fd
def add_actions(self):
''' Build Application Actions '''
from gajim import app_actions

View File

@ -646,3 +646,19 @@ def get_app_window(cls, account=None):
def load_css_config():
global css_config
css_config = CSSConfig()
def set_win_debug_mode(enable: bool) -> None:
debug_folder = Path(configpaths.get('DEBUG'))
debug_enabled = debug_folder / 'debug-enabled'
if enable:
debug_enabled.touch()
else:
if debug_enabled.exists():
debug_enabled.unlink()
def get_win_debug_mode() -> bool:
if sys.platform != 'win32':
return False
debug_folder = Path(configpaths.get('DEBUG'))
debug_enabled = debug_folder / 'debug-enabled'
return debug_enabled.exists()

View File

@ -195,6 +195,7 @@ class ConfigPaths:
# Data paths
('SECRETS_FILE', 'secrets', PathLocation.DATA, PathType.FILE),
('MY_PEER_CERTS', 'certs', PathLocation.DATA, PathType.FOLDER),
('DEBUG', 'debug', PathLocation.DATA, PathType.FOLDER),
# Config paths
('CONFIG_FILE', 'config', PathLocation.CONFIG, PathType.FILE),

View File

@ -1509,6 +1509,7 @@ $T will be replaced by auto-not-available timeout</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkFrame" id="frame3">
@ -1640,6 +1641,7 @@ $T will be replaced by auto-not-available timeout</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
@ -2384,6 +2386,23 @@ to discover one from server.</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="enable_logging">
<property name="label" translatable="yes">Enable debug logging</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="no_show_all">True</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_enable_logging_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="label">

View File

@ -13,6 +13,7 @@
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
from gi.repository import Gtk
from gi.repository import Gdk
@ -449,6 +450,11 @@ class Preferences(Gtk.ApplicationWindow):
else:
w.set_active(st)
if sys.platform == 'win32':
w = self.xml.get_object('enable_logging')
w.set_active(app.get_win_debug_mode())
w.show()
self.xml.connect_signals(self)
self.connect('key-press-event', self._on_key_press)
@ -998,3 +1004,6 @@ class Preferences(Gtk.ApplicationWindow):
else:
app.interface.instances['advanced_config'] = \
AdvancedConfigurationWindow(self)
def on_enable_logging_toggled(self, widget):
app.set_win_debug_mode(widget.get_active())