Skip to content

Commit 3a34d65

Browse files
committed
refactor: Keep logging setup in same place
Move basic console logger setup into module init the same as the structlog is - since we need logging to be configured *before* modules start creating their `logger`s.
1 parent 2a9a099 commit 3a34d65

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

cx-agent-backend/cx_agent_backend/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
"""CX demo agent package including agent definition and AgentCore-compatible REST server"""
22

3-
# Configure structured logging here during module initialization, before other local and external
4-
# imports start creating loggers:
3+
# TODO: Review how log level configuration can fit together with other settings
4+
# We need to configure logging here during module initialization, **before** other local and
5+
# external imports start creating loggers with their own default levels, formats, etc.
6+
import logging
7+
from os import environ
58
import structlog
69

10+
# Basic terminal logging:
11+
logging.basicConfig(
12+
level=environ.get("LOG_LEVEL", "INFO").upper(),
13+
format='%(asctime)s %(name)s [%(levelname)s] %(message)s',
14+
datefmt='%Y-%m-%dT%H:%M:%S'
15+
)
16+
17+
# Structured logging:
718
structlog.configure(
819
processors=[
920
structlog.stdlib.filter_by_level,

cx-agent-backend/cx_agent_backend/server.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
from fastapi import FastAPI, HTTPException, Request
99
import structlog
1010

11-
# Configure basic logging to terminal
12-
logging.basicConfig(
13-
level=logging.INFO,
14-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
15-
handlers=[
16-
logging.StreamHandler(sys.stdout)
17-
]
18-
)
19-
2011
from cx_agent_backend.infrastructure.config.container import Container
2112
from cx_agent_backend.infrastructure.config.settings import settings
2213
from cx_agent_backend.presentation.api.conversation_router import (

0 commit comments

Comments
 (0)