24 lines
		
	
	
	
		
			741 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
	
		
			741 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import inspect
 | |
| 
 | |
| def log(msg: str):
 | |
|     # Récupère la frame du context appelant
 | |
|     current_frame = inspect.currentframe()
 | |
|     previous_frame = current_frame.f_back
 | |
| 
 | |
|     # Retourne un object Traceback
 | |
|     frame_info = inspect.getframeinfo(previous_frame)
 | |
| 
 | |
|     # Récupère le nom du module appelant
 | |
|     module = inspect.getmodule(previous_frame.f_code)
 | |
|     module_name = module.__name__
 | |
| 
 | |
|     # Récupère et formatte les arguments de la fonction
 | |
|     func_args = inspect.getargvalues(previous_frame)
 | |
|     func_args = inspect.formatargvalues(
 | |
|         func_args.args,
 | |
|         func_args.varargs,
 | |
|         func_args.keywords,
 | |
|         func_args.locals
 | |
|     )
 | |
| 
 | |
|     print(f'[{module_name}:{frame_info.lineno}:{frame_info.function}{func_args}] {msg}')
 |