colored error output
This commit is contained in:
		
					parent
					
						
							
								e4d2c98fb5
							
						
					
				
			
			
				commit
				
					
						eea6c1568e
					
				
			
		
					 2 changed files with 12 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -6,6 +6,8 @@ import importlib
 | 
			
		|||
import multiprocessing as mp
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
import colorama
 | 
			
		||||
 | 
			
		||||
from logging.handlers import SysLogHandler
 | 
			
		||||
 | 
			
		||||
from ucloud.configure.main import configure_parser
 | 
			
		||||
| 
						 | 
				
			
			@ -24,11 +26,20 @@ class NoTracebackStreamHandler(logging.StreamHandler):
 | 
			
		|||
    def handle(self, record):
 | 
			
		||||
        info, cache = record.exc_info, record.exc_text
 | 
			
		||||
        record.exc_info, record.exc_text = None, None
 | 
			
		||||
 | 
			
		||||
        if record.levelname == 'WARNING':
 | 
			
		||||
            color = colorama.Fore.YELLOW
 | 
			
		||||
        elif record.levelname == 'ERROR':
 | 
			
		||||
            color = colorama.Fore.LIGHTRED_EX
 | 
			
		||||
        else:
 | 
			
		||||
            color = colorama.Fore.RED
 | 
			
		||||
        try:
 | 
			
		||||
            print(color)
 | 
			
		||||
            super().handle(record)
 | 
			
		||||
        finally:
 | 
			
		||||
            record.exc_info = info
 | 
			
		||||
            record.exc_text = cache
 | 
			
		||||
            print(colorama.Style.RESET_ALL)
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    sys.excepthook = exception_hook
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								setup.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -37,6 +37,7 @@ setup(name='ucloud',
 | 
			
		|||
          'sshtunnel',
 | 
			
		||||
          'sphinx',
 | 
			
		||||
          'pynetbox',
 | 
			
		||||
          'colorama',
 | 
			
		||||
          'sphinx-rtd-theme',
 | 
			
		||||
          'etcd3 @ https://github.com/kragniz/python-etcd3/tarball/master#egg=etcd3',
 | 
			
		||||
      ],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue