Save log file into config dir when frozen
This commit is contained in:
parent
e30527f8ce
commit
f9269d5ce0
|
@ -59,10 +59,6 @@ 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 '
|
||||||
|
@ -93,6 +89,10 @@ class GajimApplication(Gtk.Application):
|
||||||
import common.configpaths
|
import common.configpaths
|
||||||
common.configpaths.gajimpaths.init(
|
common.configpaths.gajimpaths.init(
|
||||||
self.config_path, self.profile, self.profile_separation)
|
self.config_path, self.profile, self.profile_separation)
|
||||||
|
|
||||||
|
if hasattr(sys, 'frozen'):
|
||||||
|
self.frozen_logging(common.configpaths.gajimpaths.config_root)
|
||||||
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from common import check_paths
|
from common import check_paths
|
||||||
from common import exceptions
|
from common import exceptions
|
||||||
|
@ -243,3 +243,35 @@ class GajimApplication(Gtk.Application):
|
||||||
logging_helpers.set_loglevels(string)
|
logging_helpers.set_loglevels(string)
|
||||||
self.activate()
|
self.activate()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def frozen_logging(self, path):
|
||||||
|
import warnings
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.mkdir(path, 0o700)
|
||||||
|
|
||||||
|
class MyStd(object):
|
||||||
|
_file = None
|
||||||
|
_error = None
|
||||||
|
log_file = os.path.join(path, 'gajim.log')
|
||||||
|
|
||||||
|
def write(self, text):
|
||||||
|
if self._file is None and self._error is None:
|
||||||
|
try:
|
||||||
|
self._file = open(self.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
|
||||||
|
warnings.filterwarnings(action='ignore')
|
||||||
|
|
39
src/gajim.py
39
src/gajim.py
|
@ -36,51 +36,12 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
WINDEV = False
|
|
||||||
if '--windev' in sys.argv or '-w' in sys.argv:
|
|
||||||
WINDEV = True
|
|
||||||
|
|
||||||
if os.name == 'nt' and not WINDEV:
|
|
||||||
import warnings
|
|
||||||
log_path = os.path.join(os.environ['APPDATA'], 'Gajim')
|
|
||||||
if not os.path.exists(log_path):
|
|
||||||
os.mkdir(log_path, 0o700)
|
|
||||||
log_file = os.path.join(log_path, 'gajim.log')
|
|
||||||
|
|
||||||
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
|
|
||||||
warnings.filterwarnings(action='ignore')
|
|
||||||
|
|
||||||
|
|
||||||
# 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.
|
||||||
import gi
|
import gi
|
||||||
|
|
Loading…
Reference in New Issue