Ahmedik95316 commited on
Commit
fcd0e82
·
1 Parent(s): 3c172b1

Update app/fastapi_server.py

Browse files
Files changed (1) hide show
  1. app/fastapi_server.py +5 -32
app/fastapi_server.py CHANGED
@@ -48,11 +48,11 @@ def setup_logging():
48
 
49
  # If successful, add file handler
50
  handlers.append(logging.FileHandler(log_file_path))
51
- logger.info(f"Logging to file: {log_file_path}")
52
 
53
  except (PermissionError, OSError) as e:
54
  # If file logging fails, just use console logging
55
- logger.warning(f"Cannot create log file, using console only: {e}")
56
 
57
  # Try alternative locations for file logging
58
  try:
@@ -60,9 +60,9 @@ def setup_logging():
60
  temp_log = tempfile.NamedTemporaryFile(mode='w', suffix='.log', delete=False, prefix='fastapi_')
61
  temp_log.close()
62
  handlers.append(logging.FileHandler(temp_log.name))
63
- logger.info(f"Using temporary log file: {temp_log.name}")
64
  except Exception as temp_e:
65
- logger.warning(f"Temporary file logging also failed: {temp_e}")
66
 
67
  return handlers
68
 
@@ -629,31 +629,4 @@ async def get_metrics():
629
  """
630
  Get API metrics
631
 
632
- - **returns**: Usage statistics and performance metrics
633
- """
634
- try:
635
- # Calculate metrics from rate limiting storage
636
- total_requests = sum(len(requests)
637
- for requests in rate_limit_storage.values())
638
- unique_clients = len(rate_limit_storage)
639
-
640
- metrics = {
641
- "total_requests": total_requests,
642
- "unique_clients": unique_clients,
643
- "model_version": model_manager.model_metadata.get('model_version', 'unknown'),
644
- "model_health": model_manager.health_status,
645
- "last_health_check": model_manager.last_health_check.isoformat() if model_manager.last_health_check else None,
646
- "timestamp": datetime.now().isoformat(),
647
- "environment": path_manager.environment,
648
- "available_datasets": path_manager.list_available_datasets(),
649
- "available_models": path_manager.list_available_models()
650
- }
651
-
652
- return metrics
653
-
654
- except Exception as e:
655
- logger.error(f"Metrics retrieval failed: {e}")
656
- raise HTTPException(
657
- status_code=500,
658
- detail=f"Metrics retrieval failed: {str(e)}"
659
- )
 
48
 
49
  # If successful, add file handler
50
  handlers.append(logging.FileHandler(log_file_path))
51
+ print(f"Logging to file: {log_file_path}") # Use print instead of logger
52
 
53
  except (PermissionError, OSError) as e:
54
  # If file logging fails, just use console logging
55
+ print(f"Cannot create log file, using console only: {e}")
56
 
57
  # Try alternative locations for file logging
58
  try:
 
60
  temp_log = tempfile.NamedTemporaryFile(mode='w', suffix='.log', delete=False, prefix='fastapi_')
61
  temp_log.close()
62
  handlers.append(logging.FileHandler(temp_log.name))
63
+ print(f"Using temporary log file: {temp_log.name}")
64
  except Exception as temp_e:
65
+ print(f"Temporary file logging also failed: {temp_e}")
66
 
67
  return handlers
68
 
 
629
  """
630
  Get API metrics
631
 
632
+ - **returns**: Usage statistics and performance metrics