Parse log arguments earlier

This commit is contained in:
Philipp Hörist 2017-02-25 17:21:03 +01:00
parent a40c078420
commit ddf60b01b3
2 changed files with 18 additions and 13 deletions

View File

@ -19,6 +19,8 @@
## ##
import logging import logging
import os
import sys
def parseLogLevel(arg): def parseLogLevel(arg):
""" """
@ -132,10 +134,14 @@ class FancyFormatter(logging.Formatter):
return logging.Formatter.format(self, record) return logging.Formatter.format(self, record)
def init(use_color=False): def init():
""" """
Iinitialize the logging system Iinitialize the logging system
""" """
use_color = False
if os.name != 'nt':
use_color = sys.stderr.isatty()
consoleloghandler = logging.StreamHandler() consoleloghandler = logging.StreamHandler()
consoleloghandler.setFormatter( consoleloghandler.setFormatter(
FancyFormatter( FancyFormatter(
@ -171,7 +177,7 @@ def set_quiet():
# tests # tests
if __name__ == '__main__': if __name__ == '__main__':
init(use_color=True) init()
set_loglevels('gajim.c=DEBUG,INFO') set_loglevels('gajim.c=DEBUG,INFO')

View File

@ -60,9 +60,6 @@ except ImportError:
print('PyOpenSSL not available, impossible to generate entropy', file=sys.stderr) print('PyOpenSSL not available, impossible to generate entropy', file=sys.stderr)
PYOPENSSL_PRNG_PRESENT = False PYOPENSSL_PRNG_PRESENT = False
logging_helpers.init(sys.stderr.isatty())
log = logging.getLogger('gajim.gajim')
MIN_NBXMPP_VER = "0.5.3" MIN_NBXMPP_VER = "0.5.3"
@ -264,6 +261,9 @@ class GajimApplication(Gtk.Application):
self.interface.roster.prepare_quit() self.interface.roster.prepare_quit()
def do_handle_local_options(self, options: GLib.VariantDict) -> int: def do_handle_local_options(self, options: GLib.VariantDict) -> int:
logging_helpers.init()
if options.contains('profile'): if options.contains('profile'):
# Incorporate profile name into application id # Incorporate profile name into application id
# to have a single app instance for each profile. # to have a single app instance for each profile.
@ -279,18 +279,17 @@ class GajimApplication(Gtk.Application):
from common.defs import version from common.defs import version
print(version) print(version)
return 0 return 0
if options.contains('quiet'):
logging_helpers.set_quiet(True)
if options.contains('verbose'):
logging_helpers.set_verbose(True)
if options.contains('loglevel'):
loglevel = options.lookup_value('loglevel').get_string()
logging_helpers.set_loglevels(loglevel)
return -1 return -1
def do_command_line(self, command_line: Gio.ApplicationCommandLine) -> int: def do_command_line(self, command_line: Gio.ApplicationCommandLine) -> int:
Gtk.Application.do_command_line(self, command_line) Gtk.Application.do_command_line(self, command_line)
options = command_line.get_options_dict()
if options.contains('quiet'):
logging_helpers.set_quiet()
if options.contains('verbose'):
logging_helpers.set_verbose()
if options.contains('loglevel'):
string = options.lookup_value('loglevel').get_string()
logging_helpers.set_loglevels(string)
if not command_line.get_is_remote(): if not command_line.get_is_remote():
self.activate() self.activate()
return 0 return 0