style: remove prints in codebase (#1146)

# What does this PR do?
- replace prints in codebase with logger
- update print_table to use rich Table

## Test Plan
- library client script in
https://github.com/meta-llama/llama-stack/pull/1145

```
llama stack list-providers
```
<img width="1407" alt="image"
src="https://github.com/user-attachments/assets/906b4f54-9e42-4e55-8968-7e3aa45525b2"
/>


[//]: # (## Documentation)
This commit is contained in:
Xi Yan 2025-02-18 19:41:37 -08:00 committed by GitHub
parent e8cb9e0adb
commit 37cf60b732
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 65 deletions

View file

@ -47,6 +47,8 @@ from llama_stack.providers.utils.telemetry.tracing import (
start_trace,
)
logger = logging.getLogger(__name__)
T = TypeVar("T")
@ -87,7 +89,7 @@ def convert_to_pydantic(annotation: Any, value: Any) -> Any:
try:
return [convert_to_pydantic(item_type, item) for item in value]
except Exception:
print(f"Error converting list {value} into {item_type}")
logger.error(f"Error converting list {value} into {item_type}")
return value
elif origin is dict:
@ -95,7 +97,7 @@ def convert_to_pydantic(annotation: Any, value: Any) -> Any:
try:
return {k: convert_to_pydantic(val_type, v) for k, v in value.items()}
except Exception:
print(f"Error converting dict {value} into {val_type}")
logger.error(f"Error converting dict {value} into {val_type}")
return value
try:
@ -111,9 +113,8 @@ def convert_to_pydantic(annotation: Any, value: Any) -> Any:
return convert_to_pydantic(union_type, value)
except Exception:
continue
cprint(
logger.warning(
f"Warning: direct client failed to convert parameter {value} into {annotation}: {e}",
"yellow",
)
return value
@ -152,7 +153,7 @@ class LlamaStackAsLibraryClient(LlamaStackClient):
for handler in root_logger.handlers[:]:
root_logger.removeHandler(handler)
print(f"Removed handler {handler.__class__.__name__} from root logger")
logger.info(f"Removed handler {handler.__class__.__name__} from root logger")
def request(self, *args, **kwargs):
if kwargs.get("stream"):