Spaces:
Running
Running
Updated Logs Checking
Browse files
main.py
CHANGED
|
@@ -22,6 +22,8 @@ from urllib.error import HTTPError
|
|
| 22 |
# Load optional .env if present in same directory
|
| 23 |
load_dotenv()
|
| 24 |
|
|
|
|
|
|
|
| 25 |
# ==============================================================================
|
| 26 |
# LOGGING (Task 5)
|
| 27 |
# ==============================================================================
|
|
@@ -31,10 +33,14 @@ logging.Formatter.converter = lambda *args: datetime.fromtimestamp(args[-1], tz=
|
|
| 31 |
logging.basicConfig(
|
| 32 |
level=logging.INFO,
|
| 33 |
format='[%(asctime)s] %(levelname)s: %(message)s',
|
| 34 |
-
datefmt='%I:%M:%S %p'
|
|
|
|
| 35 |
)
|
| 36 |
logger = logging.getLogger(__name__)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
# ==============================================================================
|
| 39 |
# CONFIGURATION
|
| 40 |
# ==============================================================================
|
|
@@ -1003,8 +1009,8 @@ if __name__ == "__main__":
|
|
| 1003 |
elif args.run:
|
| 1004 |
# Launch FastAPI which internally starts the loop
|
| 1005 |
port = int(os.getenv("PORT", 7860))
|
| 1006 |
-
uvicorn.run(app, host="0.0.0.0", port=port,
|
| 1007 |
else:
|
| 1008 |
# Default behavior: run FastAPI
|
| 1009 |
port = int(os.getenv("PORT", 7860))
|
| 1010 |
-
uvicorn.run(app, host="0.0.0.0", port=port,
|
|
|
|
| 22 |
# Load optional .env if present in same directory
|
| 23 |
load_dotenv()
|
| 24 |
|
| 25 |
+
import sys
|
| 26 |
+
|
| 27 |
# ==============================================================================
|
| 28 |
# LOGGING (Task 5)
|
| 29 |
# ==============================================================================
|
|
|
|
| 33 |
logging.basicConfig(
|
| 34 |
level=logging.INFO,
|
| 35 |
format='[%(asctime)s] %(levelname)s: %(message)s',
|
| 36 |
+
datefmt='%I:%M:%S %p',
|
| 37 |
+
stream=sys.stdout # Ensure logs go to stdout which HF Spaces captures reliably
|
| 38 |
)
|
| 39 |
logger = logging.getLogger(__name__)
|
| 40 |
|
| 41 |
+
# Suppress Uvicorn's default access logs (spammy) but let our root logger handle everything
|
| 42 |
+
logging.getLogger("uvicorn.access").setLevel(logging.WARNING)
|
| 43 |
+
|
| 44 |
# ==============================================================================
|
| 45 |
# CONFIGURATION
|
| 46 |
# ==============================================================================
|
|
|
|
| 1009 |
elif args.run:
|
| 1010 |
# Launch FastAPI which internally starts the loop
|
| 1011 |
port = int(os.getenv("PORT", 7860))
|
| 1012 |
+
uvicorn.run(app, host="0.0.0.0", port=port, log_config=None)
|
| 1013 |
else:
|
| 1014 |
# Default behavior: run FastAPI
|
| 1015 |
port = int(os.getenv("PORT", 7860))
|
| 1016 |
+
uvicorn.run(app, host="0.0.0.0", port=port, log_config=None)
|