chore!: Sets up google_adk for top level logger namespace. Removes --log_to_tmp option in adk web and adk api_server for the same reason.

Context: google-auth commit [1] broke adk log, because it disables the top level logger named "google", which is also adk's top level logger. We establish a separate top level logger with a different name `google_adk` to prevent this in the future.

This commit only changes google_llm.py. All other files will be changed in later commits.

[1] 77ad53eb00 (diff-e386c2b2c39b4d746c1e257f503acecbde49b1746b1a34f53b57083ed6094161)

PiperOrigin-RevId: 759872317
This commit is contained in:
Wei Sun (Jack) 2025-05-16 21:27:56 -07:00 committed by Copybara-Service
parent 021aaddf32
commit 482099c925
3 changed files with 16 additions and 36 deletions

View File

@ -408,16 +408,6 @@ def cli_eval(
default="INFO",
help="Optional. Set the logging level",
)
@click.option(
"--log_to_tmp",
is_flag=True,
show_default=True,
default=False,
help=(
"Optional. Whether to log to system temp folder instead of console."
" This is useful for local debugging."
),
)
@click.option(
"--trace_to_cloud",
is_flag=True,
@ -439,7 +429,6 @@ def cli_eval(
)
def cli_web(
agents_dir: str,
log_to_tmp: bool,
session_db_url: str = "",
log_level: str = "INFO",
allow_origins: Optional[list[str]] = None,
@ -457,10 +446,7 @@ def cli_web(
adk web --session_db_url=[db_url] --port=[port] path/to/agents_dir
"""
if log_to_tmp:
logs.log_to_tmp_folder(getattr(logging, log_level.upper()))
else:
logs.log_to_stderr(getattr(logging, log_level.upper()))
logs.setup_adk_logger(getattr(logging, log_level.upper()))
@asynccontextmanager
async def _lifespan(app: FastAPI):
@ -542,16 +528,6 @@ def cli_web(
default="INFO",
help="Optional. Set the logging level",
)
@click.option(
"--log_to_tmp",
is_flag=True,
show_default=True,
default=False,
help=(
"Optional. Whether to log to system temp folder instead of console."
" This is useful for local debugging."
),
)
@click.option(
"--trace_to_cloud",
is_flag=True,
@ -575,7 +551,6 @@ def cli_web(
)
def cli_api_server(
agents_dir: str,
log_to_tmp: bool,
session_db_url: str = "",
log_level: str = "INFO",
allow_origins: Optional[list[str]] = None,
@ -593,10 +568,7 @@ def cli_api_server(
adk api_server --session_db_url=[db_url] --port=[port] path/to/agents_dir
"""
if log_to_tmp:
logs.log_to_tmp_folder(getattr(logging, log_level.upper()))
else:
logs.log_to_stderr(getattr(logging, log_level.upper()))
logs.setup_adk_logger(getattr(logging, log_level.upper()))
config = uvicorn.Config(
get_fast_api_app(

View File

@ -14,6 +14,7 @@
import logging
import os
import sys
import tempfile
import time
@ -22,11 +23,18 @@ LOGGING_FORMAT = (
)
def log_to_stderr(level=logging.INFO):
logging.basicConfig(
level=level,
format=LOGGING_FORMAT,
)
def setup_adk_logger(level=logging.INFO):
# Configure the root logger format and level.
logging.basicConfig(level=level, format=LOGGING_FORMAT)
# Set up adk_logger and log to stderr.
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(level)
handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
adk_logger = logging.getLogger('google_adk')
adk_logger.setLevel(level)
adk_logger.addHandler(handler)
def log_to_tmp_folder(

View File

@ -36,7 +36,7 @@ from .llm_response import LlmResponse
if TYPE_CHECKING:
from .llm_request import LlmRequest
logger = logging.getLogger(__name__)
logger = logging.getLogger('google_adk.' + __name__)
_NEW_LINE = '\n'
_EXCLUDED_PART_FIELD = {'inline_data': {'data'}}