Parse log arguments earlier
This commit is contained in:
		
							parent
							
								
									a40c078420
								
							
						
					
					
						commit
						ddf60b01b3
					
				
					 2 changed files with 18 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -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')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								src/gajim.py
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue