Selaa lähdekoodia

change loglevel and fix granian on linux (#4012)

* change loglevel and fix it on linux

* run precommit

* fix that as well
Khaleel Al-Adhami 7 kuukautta sitten
vanhempi
säilyke
eea5dc1918
4 muutettua tiedostoa jossa 28 lisäystä ja 6 poistoa
  1. 1 1
      reflex/config.py
  2. 1 0
      reflex/constants/base.py
  3. 18 2
      reflex/reflex.py
  4. 8 3
      reflex/utils/exec.py

+ 1 - 1
reflex/config.py

@@ -158,7 +158,7 @@ class Config(Base):
     app_name: str
     app_name: str
 
 
     # The log level to use.
     # The log level to use.
-    loglevel: constants.LogLevel = constants.LogLevel.INFO
+    loglevel: constants.LogLevel = constants.LogLevel.DEFAULT
 
 
     # The port to run the frontend on. NOTE: When running in dev mode, the next available port will be used if this is taken.
     # The port to run the frontend on. NOTE: When running in dev mode, the next available port will be used if this is taken.
     frontend_port: int = constants.DefaultPorts.FRONTEND_PORT
     frontend_port: int = constants.DefaultPorts.FRONTEND_PORT

+ 1 - 0
reflex/constants/base.py

@@ -173,6 +173,7 @@ class LogLevel(str, Enum):
     """The log levels."""
     """The log levels."""
 
 
     DEBUG = "debug"
     DEBUG = "debug"
+    DEFAULT = "default"
     INFO = "info"
     INFO = "info"
     WARNING = "warning"
     WARNING = "warning"
     ERROR = "error"
     ERROR = "error"

+ 18 - 2
reflex/reflex.py

@@ -15,6 +15,7 @@ from reflex_cli.utils import dependency
 
 
 from reflex import constants
 from reflex import constants
 from reflex.config import get_config
 from reflex.config import get_config
+from reflex.constants.base import LogLevel
 from reflex.custom_components.custom_components import custom_components_cli
 from reflex.custom_components.custom_components import custom_components_cli
 from reflex.state import reset_disk_state_manager
 from reflex.state import reset_disk_state_manager
 from reflex.utils import console, redir, telemetry
 from reflex.utils import console, redir, telemetry
@@ -245,15 +246,30 @@ def _run(
         setup_frontend(Path.cwd())
         setup_frontend(Path.cwd())
         commands.append((frontend_cmd, Path.cwd(), frontend_port, backend))
         commands.append((frontend_cmd, Path.cwd(), frontend_port, backend))
 
 
+    # If no loglevel is specified, set the subprocesses loglevel to WARNING.
+    subprocesses_loglevel = (
+        loglevel if loglevel != LogLevel.DEFAULT else LogLevel.WARNING
+    )
+
     # In prod mode, run the backend on a separate thread.
     # In prod mode, run the backend on a separate thread.
     if backend and env == constants.Env.PROD:
     if backend and env == constants.Env.PROD:
-        commands.append((backend_cmd, backend_host, backend_port, loglevel, frontend))
+        commands.append(
+            (
+                backend_cmd,
+                backend_host,
+                backend_port,
+                subprocesses_loglevel,
+                frontend,
+            )
+        )
 
 
     # Start the frontend and backend.
     # Start the frontend and backend.
     with processes.run_concurrently_context(*commands):
     with processes.run_concurrently_context(*commands):
         # In dev mode, run the backend on the main thread.
         # In dev mode, run the backend on the main thread.
         if backend and env == constants.Env.DEV:
         if backend and env == constants.Env.DEV:
-            backend_cmd(backend_host, int(backend_port), loglevel, frontend)
+            backend_cmd(
+                backend_host, int(backend_port), subprocesses_loglevel, frontend
+            )
             # The windows uvicorn bug workaround
             # The windows uvicorn bug workaround
             # https://github.com/reflex-dev/reflex/issues/2335
             # https://github.com/reflex-dev/reflex/issues/2335
             if constants.IS_WINDOWS and exec.frontend_process:
             if constants.IS_WINDOWS and exec.frontend_process:

+ 8 - 3
reflex/utils/exec.py

@@ -16,6 +16,7 @@ import psutil
 
 
 from reflex import constants
 from reflex import constants
 from reflex.config import get_config
 from reflex.config import get_config
+from reflex.constants.base import LogLevel
 from reflex.utils import console, path_ops
 from reflex.utils import console, path_ops
 from reflex.utils.prerequisites import get_web_dir
 from reflex.utils.prerequisites import get_web_dir
 
 
@@ -201,7 +202,11 @@ def get_granian_target():
     Returns:
     Returns:
         The Granian target for the backend.
         The Granian target for the backend.
     """
     """
-    return get_app_module() + f".{constants.CompileVars.API}"
+    import reflex
+
+    app_module_path = Path(reflex.__file__).parent / "app_module_for_backend.py"
+
+    return f"{str(app_module_path)}:{constants.CompileVars.APP}.{constants.CompileVars.API}"
 
 
 
 
 def run_backend(
 def run_backend(
@@ -233,7 +238,7 @@ def run_backend(
         run_uvicorn_backend(host, port, loglevel)
         run_uvicorn_backend(host, port, loglevel)
 
 
 
 
-def run_uvicorn_backend(host, port, loglevel):
+def run_uvicorn_backend(host, port, loglevel: LogLevel):
     """Run the backend in development mode using Uvicorn.
     """Run the backend in development mode using Uvicorn.
 
 
     Args:
     Args:
@@ -253,7 +258,7 @@ def run_uvicorn_backend(host, port, loglevel):
     )
     )
 
 
 
 
-def run_granian_backend(host, port, loglevel):
+def run_granian_backend(host, port, loglevel: LogLevel):
     """Run the backend in development mode using Granian.
     """Run the backend in development mode using Granian.
 
 
     Args:
     Args: