diff --git a/openhands/cli/main.py b/openhands/cli/main.py index e704a3a889..89ed49d3ce 100644 --- a/openhands/cli/main.py +++ b/openhands/cli/main.py @@ -364,7 +364,16 @@ async def main_with_loop(loop: asyncio.AbstractEventLoop) -> None: """Runs the agent in CLI mode.""" args = parse_arguments() - logger.setLevel(logging.WARNING) + # Set log level from command line argument if provided + if args.log_level and isinstance(args.log_level, str): + log_level = getattr(logging, str(args.log_level).upper()) + logger.setLevel(log_level) + else: + # Set default log level to WARNING if no LOG_LEVEL environment variable is set + # (command line argument takes precedence over environment variable) + env_log_level = os.getenv('LOG_LEVEL') + if not env_log_level: + logger.setLevel(logging.WARNING) # Load config from toml and override with command line arguments config: OpenHandsConfig = setup_config_from_args(args) diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index d7ea41135d..47662702d0 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -790,6 +790,7 @@ async def test_config_loading_order( mock_args.llm_config = None # This should allow settings to be used # Add a file property to avoid file I/O errors mock_args.file = None + mock_args.log_level = 'INFO' mock_parse_args.return_value = mock_args # Mock read_task to return a dummy task