61 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import os as _os
 | |
| import logging as _logging
 | |
| from datetime import datetime as _dt
 | |
| from bot_libs import syms as _bot_syms
 | |
| 
 | |
| logger= _logging.getLogger(__name__)
 | |
| file_handler= None
 | |
| 
 | |
| def get_log_name():
 | |
|   now= _dt.now()
 | |
|   year= now.year
 | |
|   month= now.month
 | |
|   if month < 10: month= f'0{month}'
 | |
|   day= now.day
 | |
|   if day < 10: day= f'0{day}'
 | |
|   fname= f'battle_royale-{now.year}{month}{day}.log'
 | |
| 
 | |
|   return _os.path.join(_bot_syms.LOG_PATH, fname)
 | |
| 
 | |
| def _create_file_handler():
 | |
|   global file_handler
 | |
|   current_log_file = get_log_name()
 | |
|   file_handler = _logging.FileHandler(current_log_file, encoding='utf-8')
 | |
|   formatter = _logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
 | |
|   file_handler.setFormatter(formatter)
 | |
|   logger.addHandler(file_handler)
 | |
|   #logger.setLevel(_logging.INFO)
 | |
|   logger.setLevel(_logging.DEBUG)
 | |
|   return file_handler
 | |
| 
 | |
| def _setup_logging_file():
 | |
|   current_log_file = get_log_name()
 | |
|   
 | |
|   if not file_handler: return _create_file_handler()
 | |
|   if file_handler.baseFilename == _os.path.abspath(current_log_file): return
 | |
| 
 | |
|   logger.removeHandler(file_handler)
 | |
|   file_handler.close()
 | |
|   _create_file_handler()
 | |
| 
 | |
| def log_debug(txt):
 | |
|   print(txt)
 | |
|   _setup_logging_file()
 | |
|   logger.debug(txt)
 | |
| 
 | |
| def log_info(txt):
 | |
|   _setup_logging_file()
 | |
|   logger.info(txt)
 | |
| 
 | |
| def log_warning(txt):
 | |
|   _setup_logging_file()
 | |
|   logger.warning(txt)
 | |
| 
 | |
| def log_error(txt):
 | |
|   _setup_logging_file()
 | |
|   logger.error(txt)
 | |
| 
 | |
| def log_critical(txt):
 | |
|   _setup_logging_file()
 | |
|   logger.critical(txt)
 | 
