Save log file into config dir when frozen

This commit is contained in:
Philipp Hörist 2017-02-11 20:57:03 +01:00
parent e30527f8ce
commit f9269d5ce0
2 changed files with 36 additions and 43 deletions

View File

@ -59,10 +59,6 @@ class GajimApplication(Gtk.Application):
GLib.OptionArg.NONE,
_('Print XML stanzas and other debug '
'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,
GLib.OptionArg.STRING,
_('Use defined profile in configuration '
@ -93,6 +89,10 @@ class GajimApplication(Gtk.Application):
import common.configpaths
common.configpaths.gajimpaths.init(
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 check_paths
from common import exceptions
@ -243,3 +243,35 @@ class GajimApplication(Gtk.Application):
logging_helpers.set_loglevels(string)
self.activate()
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')

View File

@ -36,51 +36,12 @@
##
import sys
import os
if '--version' in sys.argv or '-V' in sys.argv:
from common.defs import version
print(version)
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 multiple times in every module. nbxmpp also needs GLib.
import gi