logging cleanup
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m9s
				
			
		
			
				
	
				Run linting on the backend code / Build (pull_request) Failing after 30s
				
			
		
			
				
	
				Run testing on the backend code / Build (pull_request) Failing after 1m41s
				
			
		
			
				
	
				Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 18s
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m9s
				
			Run linting on the backend code / Build (pull_request) Failing after 30s
				
			Run testing on the backend code / Build (pull_request) Failing after 1m41s
				
			Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 18s
				
			This commit is contained in:
		| @@ -1,6 +1,5 @@ | ||||
| """Module setting global parameters for the application, such as logging, cache, route generation, etc.""" | ||||
| """Module setting global parameters for the application such as cache, route generation, etc.""" | ||||
|  | ||||
| import logging | ||||
| import os | ||||
| from pathlib import Path | ||||
|  | ||||
| @@ -16,43 +15,6 @@ cache_dir_string = os.getenv('OSM_CACHE_DIR', './cache') | ||||
| OSM_CACHE_DIR = Path(cache_dir_string) | ||||
|  | ||||
|  | ||||
| # if we are in a debug (local) session, set verbose and rich logging | ||||
| debug = os.getenv('DEBUG', "false") == "true" | ||||
| if os.getenv('KUBERNETES_SERVICE_HOST', None) is not None: | ||||
|     # in that case we want to log to stdout and also to loki | ||||
|     from loki_logger_handler.loki_logger_handler import LokiLoggerHandler | ||||
|     loki_url = os.getenv('LOKI_URL') | ||||
|     if loki_url is None: | ||||
|         raise ValueError("LOKI_URL environment variable is not set") | ||||
|      | ||||
|     loki_handler = LokiLoggerHandler( | ||||
|         url = loki_url, | ||||
|         labels = {'app': 'anyway', 'environment': 'production' if debug else 'staging'} | ||||
|     ) | ||||
|     print(f"Logging to Loki at {loki_url} with {loki_handler.labels} and {debug=}") | ||||
|     if debug: | ||||
|         # we need to silence the debug logs made by the loki handler | ||||
|         logging.getLogger('urllib3.connectionpool').setLevel(logging.INFO) | ||||
|  | ||||
|         logging.basicConfig( | ||||
|             level=logging.DEBUG, | ||||
|             handlers=[loki_handler, logging.StreamHandler()] | ||||
|         ) | ||||
|     else: | ||||
|         logging.basicConfig( | ||||
|             level=logging.INFO, | ||||
|             handlers=[loki_handler, logging.StreamHandler()] | ||||
|         ) | ||||
| else: | ||||
|     # in that case we are local and we want to log to stdout only, but make it pretty | ||||
|     from rich.logging import RichHandler | ||||
|     logging.basicConfig( | ||||
|         level=logging.DEBUG, | ||||
|         format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | ||||
|         handlers=[RichHandler()] | ||||
|     ) | ||||
|  | ||||
|  | ||||
| MEMCACHED_HOST_PATH = os.getenv('MEMCACHED_HOST_PATH', None) | ||||
| if MEMCACHED_HOST_PATH == "none": | ||||
|     MEMCACHED_HOST_PATH = None | ||||
|   | ||||
| @@ -139,4 +139,4 @@ class Toilets(BaseModel) : | ||||
|      | ||||
|     class Config: | ||||
|         # This allows us to easily convert the model to and from dictionaries | ||||
|         orm_mode = True | ||||
|         from_attributes = True | ||||
		Reference in New Issue
	
	Block a user