Parcourir la source

生产日志配置。

tanlie il y a 3 jours
Parent
commit
714d281ddb
3 fichiers modifiés avec 11 ajouts et 2 suppressions
  1. 1 0
      app/app.py
  2. 6 0
      docker-compose.yaml
  3. 4 2
      ginger.py

+ 1 - 0
app/app.py

@@ -31,6 +31,7 @@ def create_app(env: str = "default"):
         from app.utils.logger import setup_logging
 
         setup_logging(app)
+        app.logger.info("Application initialized in %s mode", env)
     except Exception:
         # keep app creation robust even if logging setup fails
         pass

+ 6 - 0
docker-compose.yaml

@@ -3,8 +3,14 @@ services:
     image: ginger:latest
     container_name: ginger
     command: ["uwsgi", "--ini", "/app/uwsgi.ini"]
+    env_file:
+      - .env
+    environment:
+      FLASK_ENV: production
+      LOG_FILE: /app/logs/app.log
     ports:
       - "5000:5000"
     volumes:
       - /home/tanlie/logs/ginger:/app/logs
+      - /home/tanlie/config/.env:/app/.env
     restart: unless-stopped

+ 4 - 2
ginger.py

@@ -1,11 +1,13 @@
 """Application entrypoint."""
+import os
+
 from werkzeug.exceptions import HTTPException
 
 from app.app import create_app
 from app.exceptions.api_exception import APIException
 from app.exceptions.common_error import ServerError
 
-app = create_app("development")
+app = create_app(os.getenv("FLASK_ENV", "development"))
 
 
 @app.errorhandler(Exception)
@@ -31,4 +33,4 @@ def framework_error(e):
 
 
 if __name__ == "__main__":
-    app.run(host="0.0.0.0", port=5000, debug=True)
+    app.run(host="0.0.0.0", port=5000, debug=app.config.get("DEBUG", False), use_reloader=False)