diff --git a/gajim/application.py b/gajim/application.py
index 0ea34f025..274852847 100644
--- a/gajim/application.py
+++ b/gajim/application.py
@@ -34,6 +34,8 @@
# along with Gajim. If not, see .
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
diff --git a/gajim/common/app.py b/gajim/common/app.py
index b8dd434a1..5ca859046 100644
--- a/gajim/common/app.py
+++ b/gajim/common/app.py
@@ -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()
diff --git a/gajim/common/configpaths.py b/gajim/common/configpaths.py
index 020e85244..0649d6f2a 100644
--- a/gajim/common/configpaths.py
+++ b/gajim/common/configpaths.py
@@ -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),
diff --git a/gajim/data/gui/preferences_window.ui b/gajim/data/gui/preferences_window.ui
index 67814e62b..0ba4e66fa 100644
--- a/gajim/data/gui/preferences_window.ui
+++ b/gajim/data/gui/preferences_window.ui
@@ -1509,6 +1509,7 @@ $T will be replaced by auto-not-available timeout
vertical
12
+
+
@@ -2384,6 +2386,23 @@ to discover one from server.
0
+
+
+
+ False
+ True
+ 1
+
+
diff --git a/gajim/gtk/preferences.py b/gajim/gtk/preferences.py
index d2407ad2f..b1988a96f 100644
--- a/gajim/gtk/preferences.py
+++ b/gajim/gtk/preferences.py
@@ -13,6 +13,7 @@
# along with Gajim. If not, see .
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())