mirror of
				https://github.com/KevinMidboe/transatlanticTorrentExpress.git
				synced 2025-10-29 18:00:19 +00:00 
			
		
		
		
	Make elastic logging optional with config flag
This commit is contained in:
		
							
								
								
									
										11
									
								
								logger.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								logger.py
									
									
									
									
									
								
							| @@ -74,7 +74,7 @@ class ESHandler(logging.Handler): | ||||
|         return response | ||||
|     except urllib.error.HTTPError as e: | ||||
|         print('Unable to reach elastic, error:', e) | ||||
|         return asdf | ||||
|         return | ||||
|  | ||||
| class ElasticFieldParameterAdapter(logging.LoggerAdapter): | ||||
|   def __init__(self, logger, extra={}): | ||||
| @@ -93,12 +93,15 @@ esHost = config['ELASTIC']['host'] | ||||
| esPort = config['ELASTIC']['port'] | ||||
| esSSL = config['ELASTIC']['ssl'] | ||||
| esApiKey = config['ELASTIC']['api_key'] | ||||
| eh = ESHandler(host=esHost, port=esPort, ssl=esSSL, apiKey=esApiKey) | ||||
| eh.setLevel(logging.DEBUG) | ||||
| esEnabled = config['ELASTIC']['enabled'] | ||||
| if esEnabled == 'True': | ||||
|   eh = ESHandler(host=esHost, port=esPort, ssl=esSSL, apiKey=esApiKey) | ||||
|   eh.setLevel(logging.DEBUG) | ||||
|  | ||||
| formatter = logging.Formatter('%(asctime)s %(levelname)8s | %(message)s') | ||||
| fh.setFormatter(formatter) | ||||
| logger.addHandler(fh) | ||||
| logger.addHandler(ch) | ||||
| logger.addHandler(eh) | ||||
| if esEnabled == 'True': | ||||
|   logger.addHandler(eh) | ||||
| logger = ElasticFieldParameterAdapter(logger) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user