Philipp Hörist pushed to branch master at gajim / gajim

Commits:

2 changed files:

Changes:

  • src/common/logging_helpers.py
    ... ... @@ -19,6 +19,8 @@
    19 19
     ##
    
    20 20
     
    
    21 21
     import logging
    
    22
    +import os
    
    23
    +import sys
    
    22 24
     
    
    23 25
     def parseLogLevel(arg):
    
    24 26
         """
    
    ... ... @@ -132,10 +134,14 @@ class FancyFormatter(logging.Formatter):
    132 134
             return logging.Formatter.format(self, record)
    
    133 135
     
    
    134 136
     
    
    135
    -def init(use_color=False):
    
    137
    +def init():
    
    136 138
         """
    
    137 139
         Iinitialize the logging system
    
    138 140
         """
    
    141
    +    use_color = False
    
    142
    +    if os.name != 'nt':
    
    143
    +        use_color = sys.stderr.isatty()
    
    144
    +
    
    139 145
         consoleloghandler = logging.StreamHandler()
    
    140 146
         consoleloghandler.setFormatter(
    
    141 147
                 FancyFormatter(
    
    ... ... @@ -171,7 +177,7 @@ def set_quiet():
    171 177
     
    
    172 178
     # tests
    
    173 179
     if __name__ == '__main__':
    
    174
    -    init(use_color=True)
    
    180
    +    init()
    
    175 181
     
    
    176 182
         set_loglevels('gajim.c=DEBUG,INFO')
    
    177 183
     
    

  • src/gajim.py
    ... ... @@ -60,9 +60,6 @@ except ImportError:
    60 60
         print('PyOpenSSL not available, impossible to generate entropy', file=sys.stderr)
    
    61 61
         PYOPENSSL_PRNG_PRESENT = False
    
    62 62
     
    
    63
    -logging_helpers.init(sys.stderr.isatty())
    
    64
    -log = logging.getLogger('gajim.gajim')
    
    65
    -
    
    66 63
     MIN_NBXMPP_VER = "0.5.3"
    
    67 64
     
    
    68 65
     
    
    ... ... @@ -264,6 +261,9 @@ class GajimApplication(Gtk.Application):
    264 261
                 self.interface.roster.prepare_quit()
    
    265 262
     
    
    266 263
         def do_handle_local_options(self, options: GLib.VariantDict) -> int:
    
    264
    +
    
    265
    +        logging_helpers.init()
    
    266
    +
    
    267 267
             if options.contains('profile'):
    
    268 268
                 # Incorporate profile name into application id
    
    269 269
                 # to have a single app instance for each profile.
    
    ... ... @@ -279,18 +279,17 @@ class GajimApplication(Gtk.Application):
    279 279
                 from common.defs import version
    
    280 280
                 print(version)
    
    281 281
                 return 0
    
    282
    +        if options.contains('quiet'):
    
    283
    +            logging_helpers.set_quiet(True)
    
    284
    +        if options.contains('verbose'):
    
    285
    +            logging_helpers.set_verbose(True)
    
    286
    +        if options.contains('loglevel'):
    
    287
    +            loglevel = options.lookup_value('loglevel').get_string()
    
    288
    +            logging_helpers.set_loglevels(loglevel)
    
    282 289
             return -1
    
    283 290
     
    
    284 291
         def do_command_line(self, command_line: Gio.ApplicationCommandLine) -> int:
    
    285 292
             Gtk.Application.do_command_line(self, command_line)
    
    286
    -        options = command_line.get_options_dict()
    
    287
    -        if options.contains('quiet'):
    
    288
    -            logging_helpers.set_quiet()
    
    289
    -        if options.contains('verbose'):
    
    290
    -            logging_helpers.set_verbose()
    
    291
    -        if options.contains('loglevel'):
    
    292
    -            string = options.lookup_value('loglevel').get_string()
    
    293
    -            logging_helpers.set_loglevels(string)
    
    294 293
             if not command_line.get_is_remote():
    
    295 294
                 self.activate()
    
    296 295
             return 0