mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-16 04:02:55 -06:00
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:
parent
021aaddf32
commit
482099c925
@ -408,16 +408,6 @@ def cli_eval(
|
|||||||
default="INFO",
|
default="INFO",
|
||||||
help="Optional. Set the logging level",
|
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(
|
@click.option(
|
||||||
"--trace_to_cloud",
|
"--trace_to_cloud",
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
@ -439,7 +429,6 @@ def cli_eval(
|
|||||||
)
|
)
|
||||||
def cli_web(
|
def cli_web(
|
||||||
agents_dir: str,
|
agents_dir: str,
|
||||||
log_to_tmp: bool,
|
|
||||||
session_db_url: str = "",
|
session_db_url: str = "",
|
||||||
log_level: str = "INFO",
|
log_level: str = "INFO",
|
||||||
allow_origins: Optional[list[str]] = None,
|
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
|
adk web --session_db_url=[db_url] --port=[port] path/to/agents_dir
|
||||||
"""
|
"""
|
||||||
if log_to_tmp:
|
logs.setup_adk_logger(getattr(logging, log_level.upper()))
|
||||||
logs.log_to_tmp_folder(getattr(logging, log_level.upper()))
|
|
||||||
else:
|
|
||||||
logs.log_to_stderr(getattr(logging, log_level.upper()))
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def _lifespan(app: FastAPI):
|
async def _lifespan(app: FastAPI):
|
||||||
@ -542,16 +528,6 @@ def cli_web(
|
|||||||
default="INFO",
|
default="INFO",
|
||||||
help="Optional. Set the logging level",
|
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(
|
@click.option(
|
||||||
"--trace_to_cloud",
|
"--trace_to_cloud",
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
@ -575,7 +551,6 @@ def cli_web(
|
|||||||
)
|
)
|
||||||
def cli_api_server(
|
def cli_api_server(
|
||||||
agents_dir: str,
|
agents_dir: str,
|
||||||
log_to_tmp: bool,
|
|
||||||
session_db_url: str = "",
|
session_db_url: str = "",
|
||||||
log_level: str = "INFO",
|
log_level: str = "INFO",
|
||||||
allow_origins: Optional[list[str]] = None,
|
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
|
adk api_server --session_db_url=[db_url] --port=[port] path/to/agents_dir
|
||||||
"""
|
"""
|
||||||
if log_to_tmp:
|
logs.setup_adk_logger(getattr(logging, log_level.upper()))
|
||||||
logs.log_to_tmp_folder(getattr(logging, log_level.upper()))
|
|
||||||
else:
|
|
||||||
logs.log_to_stderr(getattr(logging, log_level.upper()))
|
|
||||||
|
|
||||||
config = uvicorn.Config(
|
config = uvicorn.Config(
|
||||||
get_fast_api_app(
|
get_fast_api_app(
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -22,11 +23,18 @@ LOGGING_FORMAT = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def log_to_stderr(level=logging.INFO):
|
def setup_adk_logger(level=logging.INFO):
|
||||||
logging.basicConfig(
|
# Configure the root logger format and level.
|
||||||
level=level,
|
logging.basicConfig(level=level, format=LOGGING_FORMAT)
|
||||||
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(
|
def log_to_tmp_folder(
|
||||||
|
@ -36,7 +36,7 @@ from .llm_response import LlmResponse
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .llm_request import LlmRequest
|
from .llm_request import LlmRequest
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger('google_adk.' + __name__)
|
||||||
|
|
||||||
_NEW_LINE = '\n'
|
_NEW_LINE = '\n'
|
||||||
_EXCLUDED_PART_FIELD = {'inline_data': {'data'}}
|
_EXCLUDED_PART_FIELD = {'inline_data': {'data'}}
|
||||||
|
Loading…
Reference in New Issue
Block a user