8000 chore!: Sets up `google_adk` for top level logger namespace. Removes … · liunix61/adk-python@482099c · GitHub
[go: up one dir, main page]

Skip to content

Commit 482099c

Browse files
Jacksunweicopybara-github
authored andcommitted
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] googleapis/google-auth-library-python@77ad53e#diff-e386c2b2c39b4d746c1e257f503acecbde49b1746b1a34f53b57083ed6094161 PiperOrigin-RevId: 759872317
1 parent 021aadd commit 482099c

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

src/google/adk/cli/cli_tools_click.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,6 @@ async def _collect_eval_results() -> list[EvalCaseResult]:
408408
default="INFO",
409409
help="Optional. Set the logging level",
410410
)
411-
@click.option(
412-
"--log_to_tmp",
413-
is_flag=True,
414-
show_default=True,
415-
default=False,
416-
help=(
417-
"Optional. Whether to log to system temp folder instead of console."
418-
" This is useful for local debugging."
419-
),
420-
)
421411
@click.option(
422412
"--trace_to_cloud",
423413
is_flag=True,
@@ -439,7 +429,6 @@ async def _collect_eval_results() -> list[EvalCaseResult]:
439429
)
440430
def cli_web(
441431
agents_dir: str,
442-
log_to_tmp: bool,
443432
session_db_url: str = "",
444433
log_level: str = "INFO",
445434
allow_origins: Optional[list[str]] = None,
@@ -457,10 +446,7 @@ def cli_web(
457446
458447
adk web --session_db_url=[db_url] --port=[port] path/to/agents_dir
459448
"""
460-
if log_to_tmp:
461-
logs.log_to_tmp_folder(getattr(logging, log_level.upper()))
462-
else:
463-
logs.log_to_stderr(getattr(logging, log_level.upper()))
449+
logs.setup_adk_logger(getattr(logging, log_level.upper()))
464450

465451
@asynccontextmanager
466452
async def _lifespan(app: FastAPI):
@@ -542,16 +528,6 @@ async def _lifespan(app: FastAPI):
542528
default="INFO",
543529
help="Optional. Set the logging level",
544530
)
545-
@click.option(
546-
"--log_to_tmp",
547-
is_flag=True,
548-
show_default=True,
549-
default=False,
550-
help=(
551-
"Optional. Whether to log to system temp folder instead of console."
552-
" This is useful for local debugging."
553-
),
554-
)
555531
@click.option(
556532
"--trace_to_cloud",
557533
is_flag=True,
@@ -575,7 +551,6 @@ async def _lifespan(app: FastAPI):
575551
)
576552
def cli_api_server(
577553
agents_dir: str,
578-
log_to_tmp: bool,
579554
session_db_url: str = "",
580555
log_level: str = "INFO",
581556
allow_origins: Optional[list[str]] = None,
@@ -593,10 +568,7 @@ def cli_api_server(
593568
594569
adk api_server --session_db_url=[db_url] --port=[port] path/to/agents_dir
595570
"""
596-
if log_to_tmp:
597-
logs.log_to_tmp_folder(getattr(logging, log_level.upper()))
598-
else:
599-
logs.log_to_stderr(getattr(logging, log_level.upper()))
571+
logs.setup_adk_logger(getattr(logging, log_level.upper()))
600572

601573
config = uvicorn.Config(
602574
get_fast_api_app(

src/google/adk/cli/utils/logs.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import logging
1616
import os
17+
import sys
1718
import tempfile
1819
import time
1920

@@ -22,11 +23,18 @@
2223
)
2324

2425

25-
def log_to_stderr(level=logging.INFO):
26-
logging.basicConfig(
27-
level=level,
28-
format=LOGGING_FORMAT,
29-
)
26+
def setup_adk_logger(level=logging.INFO):
27+
# Configure the root logger format and level.
28+
logging.basicConfig(level=level, format=LOGGING_FORMAT)
29+
30+
# Set up adk_logger and log to stderr.
31+
handler = logging.StreamHandler(sys.stderr)
32+
handler.setLevel(level)
33+
handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
34+
35+
adk_logger = logging.getLogger('google_adk')
36+
adk_logger.setLevel(level)
37+
adk_logger.addHandler(handler)
3038

3139

3240
def log_to_tmp_folder(

src/google/adk/models/google_llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
if TYPE_CHECKING:
3737
from .llm_request import LlmRequest
3838

39-
logger = logging.getLogger(__name__)
39+
logger = logging.getLogger('google_adk.' + __name__)
4040

4141
_NEW_LINE = '\n'
4242
_EXCLUDED_PART_FIELD = {'inline_data': {'data'}}

0 commit comments

Comments
 (0)
0