fix openhands cli loglevel (#9382)

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
tangwei12 2025-07-08 22:07:13 +08:00 committed by GitHub
parent 3f5a5005a2
commit ea07570f62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -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)

View File

@ -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