From ddf60b01b37e407de668c5240759897b2d9989c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 25 Feb 2017 17:21:03 +0100 Subject: [PATCH] Parse log arguments earlier --- src/common/logging_helpers.py | 10 ++++++++-- src/gajim.py | 21 ++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/common/logging_helpers.py b/src/common/logging_helpers.py index 1d6312684..30aeddddc 100644 --- a/src/common/logging_helpers.py +++ b/src/common/logging_helpers.py @@ -19,6 +19,8 @@ ## import logging +import os +import sys def parseLogLevel(arg): """ @@ -132,10 +134,14 @@ class FancyFormatter(logging.Formatter): return logging.Formatter.format(self, record) -def init(use_color=False): +def init(): """ Iinitialize the logging system """ + use_color = False + if os.name != 'nt': + use_color = sys.stderr.isatty() + consoleloghandler = logging.StreamHandler() consoleloghandler.setFormatter( FancyFormatter( @@ -171,7 +177,7 @@ def set_quiet(): # tests if __name__ == '__main__': - init(use_color=True) + init() set_loglevels('gajim.c=DEBUG,INFO') diff --git a/src/gajim.py b/src/gajim.py index 59e3b126b..607b39d75 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -60,9 +60,6 @@ except ImportError: print('PyOpenSSL not available, impossible to generate entropy', file=sys.stderr) PYOPENSSL_PRNG_PRESENT = False -logging_helpers.init(sys.stderr.isatty()) -log = logging.getLogger('gajim.gajim') - MIN_NBXMPP_VER = "0.5.3" @@ -264,6 +261,9 @@ class GajimApplication(Gtk.Application): self.interface.roster.prepare_quit() def do_handle_local_options(self, options: GLib.VariantDict) -> int: + + logging_helpers.init() + if options.contains('profile'): # Incorporate profile name into application id # to have a single app instance for each profile. @@ -279,18 +279,17 @@ class GajimApplication(Gtk.Application): from common.defs import version print(version) 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 def do_command_line(self, command_line: Gio.ApplicationCommandLine) -> int: 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(): self.activate() return 0