| 1 |
import os |
| 2 |
import logging |
| 3 |
|
| 4 |
logger: logging.Logger = logging.getLogger("anthropic") |
| 5 |
httpx_logger: logging.Logger = logging.getLogger("httpx2") |
| 6 |
|
| 7 |
|
| 8 |
def _basic_config() -> None: |
| 9 |
# e.g. [2023-10-05 14:12:26 - anthropic._base_client:818 - DEBUG] HTTP Request: POST http://127.0.0.1:4010/foo/bar "200 OK" |
| 10 |
logging.basicConfig( |
| 11 |
format="[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s", |
| 12 |
datefmt="%Y-%m-%d %H:%M:%S", |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
def setup_logging() -> None: |
| 17 |
env = os.environ.get("ANTHROPIC_LOG") |
| 18 |
if env == "debug": |
| 19 |
_basic_config() |
| 20 |
logger.setLevel(logging.DEBUG) |
| 21 |
httpx_logger.setLevel(logging.DEBUG) |
| 22 |
elif env == "info": |
| 23 |
_basic_config() |
| 24 |
logger.setLevel(logging.INFO) |
| 25 |
httpx_logger.setLevel(logging.INFO) |