Add commandline option for logging on windows
Redirect all output to one log file or if -w is provided do not redirect output
This commit is contained in:
parent
815ecdcf47
commit
2676d7ea94
|
@ -50,6 +50,10 @@ class GajimApplication(Gtk.Application):
|
||||||
GLib.OptionArg.NONE,
|
GLib.OptionArg.NONE,
|
||||||
_('Print xml stanzas and other debug '
|
_('Print xml stanzas and other debug '
|
||||||
'information'))
|
'information'))
|
||||||
|
self.add_main_option('windev', ord('w'), GLib.OptionFlags.NONE,
|
||||||
|
GLib.OptionArg.NONE,
|
||||||
|
_('Print stdout/stderr to the console '
|
||||||
|
'on Windows'))
|
||||||
self.add_main_option('profile', ord('p'), GLib.OptionFlags.NONE,
|
self.add_main_option('profile', ord('p'), GLib.OptionFlags.NONE,
|
||||||
GLib.OptionArg.STRING,
|
GLib.OptionArg.STRING,
|
||||||
_('Use defined profile in configuration '
|
_('Use defined profile in configuration '
|
||||||
|
@ -119,26 +123,6 @@ class GajimApplication(Gtk.Application):
|
||||||
# libintl.bindtextdomain('gajim_plugins', plugins_locale_dir)
|
# libintl.bindtextdomain('gajim_plugins', plugins_locale_dir)
|
||||||
# libintl.bind_textdomain_codeset('gajim_plugins', 'UTF-8')
|
# libintl.bind_textdomain_codeset('gajim_plugins', 'UTF-8')
|
||||||
|
|
||||||
class MyStderr(object):
|
|
||||||
_file = None
|
|
||||||
_error = None
|
|
||||||
def write(self, text):
|
|
||||||
fname = os.path.join(common.configpaths.gajimpaths.cache_root,
|
|
||||||
os.path.split(sys.executable)[1]+'.log')
|
|
||||||
if self._file is None and self._error is None:
|
|
||||||
try:
|
|
||||||
self._file = open(fname, 'a')
|
|
||||||
except Exception as details:
|
|
||||||
self._error = details
|
|
||||||
if self._file is not None:
|
|
||||||
self._file.write(text)
|
|
||||||
self._file.flush()
|
|
||||||
def flush(self):
|
|
||||||
if self._file is not None:
|
|
||||||
self._file.flush()
|
|
||||||
|
|
||||||
sys.stderr = MyStderr()
|
|
||||||
|
|
||||||
# PyGTK2.10+ only throws a warning
|
# PyGTK2.10+ only throws a warning
|
||||||
warnings.filterwarnings('error', module='Gtk')
|
warnings.filterwarnings('error', module='Gtk')
|
||||||
try:
|
try:
|
||||||
|
|
37
src/gajim.py
37
src/gajim.py
|
@ -36,25 +36,48 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
if '--version' in sys.argv or '-V' in sys.argv:
|
if '--version' in sys.argv or '-V' in sys.argv:
|
||||||
from common.defs import version
|
from common.defs import version
|
||||||
print(version)
|
print(version)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
import os
|
WINDEV = False
|
||||||
import warnings
|
if '--windev' in sys.argv or '-w' in sys.argv:
|
||||||
|
WINDEV = True
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt' and not WINDEV:
|
||||||
log_path = os.path.join(os.environ['APPDATA'], 'Gajim')
|
log_path = os.path.join(os.environ['APPDATA'], 'Gajim')
|
||||||
if not os.path.exists(log_path):
|
if not os.path.exists(log_path):
|
||||||
os.mkdir(log_path, 0o700)
|
os.mkdir(log_path, 0o700)
|
||||||
log_file = os.path.join(log_path, 'gajim.log')
|
log_file = os.path.join(log_path, 'gajim.log')
|
||||||
fout = open(log_file, 'a')
|
|
||||||
sys.stdout = fout
|
|
||||||
sys.stderr = fout
|
|
||||||
|
|
||||||
warnings.filterwarnings(action='ignore')
|
class MyStd(object):
|
||||||
|
_file = None
|
||||||
|
_error = None
|
||||||
|
|
||||||
|
def write(self, text):
|
||||||
|
if self._file is None and self._error is None:
|
||||||
|
try:
|
||||||
|
self._file = open(log_file, 'a')
|
||||||
|
except Exception as details:
|
||||||
|
self._error = details
|
||||||
|
if self._file is not None:
|
||||||
|
self._file.write(text)
|
||||||
|
self._file.flush()
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
if self._file is not None:
|
||||||
|
self._file.flush()
|
||||||
|
|
||||||
|
def isatty(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
outerr = MyStd()
|
||||||
|
sys.stdout = outerr
|
||||||
|
sys.stderr = outerr
|
||||||
|
|
||||||
|
|
||||||
# Test here for all required versions so we dont have to
|
# Test here for all required versions so we dont have to
|
||||||
# test multiple times in every module. nbxmpp also needs GLib.
|
# test multiple times in every module. nbxmpp also needs GLib.
|
||||||
|
|
Loading…
Reference in New Issue