Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/+explicit-loglevel-info.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An explicit `--loglevel info` is no longer ignored when INFO is already the current level. Like any other `--loglevel` value, it now reaches `REFLEX_LOGLEVEL` and overrides a `loglevel` set in `rxconfig.py`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The root-package release rule requires a performance fragment for this production-code change, but this fragment is categorized as bugfix. Add the required .performance.md fragment or apply the documented skip-changelog waiver.

(Based on your team's feedback about root-package news fragments.)

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At news/+explicit-loglevel-info.bugfix.md, line 1:

<comment>The root-package release rule requires a `performance` fragment for this production-code change, but this fragment is categorized as `bugfix`. Add the required `.performance.md` fragment or apply the documented `skip-changelog` waiver.

(Based on your team's feedback about root-package news fragments.) </comment>

<file context>
@@ -0,0 +1 @@
+An explicit `--loglevel info` is no longer ignored when INFO is already the current level. Like any other `--loglevel` value, it now reaches `REFLEX_LOGLEVEL` and overrides a `loglevel` set in `rxconfig.py`.
</file context>

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`reflex deploy --loglevel info` now shows the deployment progress and success messages after the export step, as `REFLEX_LOGLEVEL=info reflex deploy` does. The flag was ignored because INFO was already the current level.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import os
from typing import TYPE_CHECKING

import click
Expand All @@ -16,13 +17,17 @@
def set_loglevel(ctx: click.Context, self: click.Parameter, value: str | None):
"""Set the log level.
An explicit level is always exported as ``REFLEX_LOGLEVEL`` so the app's
config picks it up, even when it equals the current level.
Args:
ctx: The click context.
self: The click command.
value: The log level to set.
"""
if value is not None:
console.set_log_level(value)
os.environ["REFLEX_LOGLEVEL"] = value


loglevel_option = click.option(
Expand Down
5 changes: 5 additions & 0 deletions reflex/utils/cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import os
from typing import TYPE_CHECKING

import click
Expand All @@ -15,6 +16,9 @@
def set_loglevel(ctx: click.Context, self: click.Parameter, value: str | None):
"""Set the log level.
An explicit level is always exported as ``REFLEX_LOGLEVEL`` so the config
picks it up, even when it equals the current level.
Args:
ctx: The click context.
self: The click command.
Expand All @@ -23,6 +27,7 @@ def set_loglevel(ctx: click.Context, self: click.Parameter, value: str | None):
if value is not None:
loglevel = constants.LogLevel.from_string(value)
console.set_log_level(loglevel)
os.environ["REFLEX_LOGLEVEL"] = value


loglevel_option = click.option(
Expand Down
48 changes: 48 additions & 0 deletions tests/units/reflex_cli/utils/test_cli_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Tests for the shared click options of the hosting CLI."""

import os

import click
import pytest
from click.testing import CliRunner
from reflex_base.config import Config
from reflex_base.constants import LogLevel
from reflex_base.utils import log
from reflex_cli.utils.cli_options import loglevel_option


@click.command()
@loglevel_option
def _loglevel_command():
"""Carry only the --loglevel option."""


@pytest.mark.parametrize(
"rxconfig_loglevel",
[LogLevel.DEFAULT, LogLevel.WARNING],
ids=["rxconfig_default", "rxconfig_warning"],
)
def test_explicit_loglevel_is_honoured_when_level_is_unchanged(
monkeypatch: pytest.MonkeyPatch, rxconfig_loglevel: LogLevel
):
"""An explicit --loglevel info reaches the config even when INFO is already the level.
`reflex deploy` takes its --loglevel from this option, and the export step
reads the level back from the config.
Args:
monkeypatch: The pytest monkeypatch fixture.
rxconfig_loglevel: The loglevel the app's rxconfig.py sets.
"""
# Set before deleting so teardown also removes the value the CLI writes.
monkeypatch.setenv("REFLEX_LOGLEVEL", "")
monkeypatch.delenv("REFLEX_LOGLEVEL")
monkeypatch.setattr(log, "_log_level", LogLevel.INFO)

result = CliRunner().invoke(_loglevel_command, ["--loglevel", "info"])

assert result.exit_code == 0
env_loglevel = os.environ.get("REFLEX_LOGLEVEL")
assert env_loglevel == "info"
assert Config(app_name="demo", loglevel=rxconfig_loglevel).loglevel is LogLevel.INFO
assert log.get_log_level() is LogLevel.INFO
46 changes: 46 additions & 0 deletions tests/units/utils/test_cli_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Tests for the shared click options of the reflex CLI."""

import os

import click
import pytest
from click.testing import CliRunner
from reflex_base.config import Config
from reflex_base.constants import LogLevel
from reflex_base.utils import log

from reflex.utils.cli_options import loglevel_option


@click.command()
@loglevel_option
def _loglevel_command():
"""Carry only the --loglevel option."""


@pytest.mark.parametrize(
"rxconfig_loglevel",
[LogLevel.DEFAULT, LogLevel.WARNING],
ids=["rxconfig_default", "rxconfig_warning"],
)
def test_explicit_loglevel_is_honoured_when_level_is_unchanged(
monkeypatch: pytest.MonkeyPatch, rxconfig_loglevel: LogLevel
):
"""An explicit --loglevel info reaches the config even when INFO is already the level.
Args:
monkeypatch: The pytest monkeypatch fixture.
rxconfig_loglevel: The loglevel the app's rxconfig.py sets.
"""
# Set before deleting so teardown also removes the value the CLI writes.
monkeypatch.setenv("REFLEX_LOGLEVEL", "")
monkeypatch.delenv("REFLEX_LOGLEVEL")
monkeypatch.setattr(log, "_log_level", LogLevel.INFO)

result = CliRunner().invoke(_loglevel_command, ["--loglevel", "info"])

assert result.exit_code == 0
env_loglevel = os.environ.get("REFLEX_LOGLEVEL")
assert env_loglevel == "info"
assert Config(app_name="demo", loglevel=rxconfig_loglevel).loglevel is LogLevel.INFO
assert log.get_log_level() is LogLevel.INFO
Loading