Skip to content

Commit d8464a0

Browse files
committed
default logging via basicConfig
1 parent aa6f7e3 commit d8464a0

File tree

9 files changed

+44
-59
lines changed

9 files changed

+44
-59
lines changed

core/src/utcp/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import logging
22
import sys
33

4-
logger = logging.getLogger("utcp")
5-
6-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
7-
handler = logging.StreamHandler(sys.stderr)
8-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
9-
logger.addHandler(handler)
10-
logger.setLevel(logging.INFO)
4+
logging.basicConfig(
5+
level=logging.INFO,
6+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
7+
)

plugins/communication_protocols/cli/src/utcp_cli/cli_communication_protocol.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
from utcp_cli.cli_call_template import CliCallTemplate, CliCallTemplateSerializer
3333
import logging
3434

35-
logger = logging.getLogger(__name__)
36-
37-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
38-
handler = logging.StreamHandler(sys.stderr)
39-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
40-
logger.addHandler(handler)
41-
logger.setLevel(logging.INFO)
35+
logging.basicConfig(
36+
level=logging.INFO,
37+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
38+
)
4239

40+
logger = logging.getLogger(__name__)
4341

4442
class CliCommunicationProtocol(CommunicationProtocol):
4543
"""REQUIRED

plugins/communication_protocols/gql/src/utcp_gql/gql_communication_protocol.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
from utcp.shared.auth import ApiKeyAuth, BasicAuth, OAuth2Auth
1212
import logging
1313

14-
logger = logging.getLogger(__name__)
15-
16-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
17-
handler = logging.StreamHandler(sys.stderr)
18-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
19-
logger.addHandler(handler)
20-
logger.setLevel(logging.INFO)
14+
logging.basicConfig(
15+
level=logging.INFO,
16+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
17+
)
2118

19+
logger = logging.getLogger(__name__)
2220

2321
class GraphQLClientTransport(ClientTransportInterface):
2422
"""

plugins/communication_protocols/http/src/utcp_http/http_communication_protocol.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@
3535
from utcp_http.openapi_converter import OpenApiConverter
3636
import logging
3737

38-
logger = logging.getLogger(__name__)
38+
logging.basicConfig(
39+
level=logging.INFO,
40+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
41+
)
3942

40-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
41-
handler = logging.StreamHandler(sys.stderr)
42-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
43-
logger.addHandler(handler)
44-
logger.setLevel(logging.INFO)
43+
logger = logging.getLogger(__name__)
4544

4645
class HttpCommunicationProtocol(CommunicationProtocol):
4746
"""REQUIRED

plugins/communication_protocols/http/src/utcp_http/sse_communication_protocol.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
import traceback
2121
import logging
2222

23-
logger = logging.getLogger(__name__)
23+
logging.basicConfig(
24+
level=logging.INFO,
25+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
26+
)
2427

25-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
26-
handler = logging.StreamHandler(sys.stderr)
27-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
28-
logger.addHandler(handler)
29-
logger.setLevel(logging.INFO)
28+
logger = logging.getLogger(__name__)
3029

3130
class SseCommunicationProtocol(CommunicationProtocol):
3231
"""REQUIRED

plugins/communication_protocols/http/src/utcp_http/streamable_http_communication_protocol.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
from aiohttp import ClientSession, BasicAuth as AiohttpBasicAuth, ClientResponse
1818
import logging
1919

20-
logger = logging.getLogger(__name__)
20+
logging.basicConfig(
21+
level=logging.INFO,
22+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
23+
)
2124

22-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
23-
handler = logging.StreamHandler(sys.stderr)
24-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
25-
logger.addHandler(handler)
26-
logger.setLevel(logging.INFO)
25+
logger = logging.getLogger(__name__)
2726

2827
class StreamableHttpCommunicationProtocol(CommunicationProtocol):
2928
"""REQUIRED

plugins/communication_protocols/mcp/src/utcp_mcp/mcp_communication_protocol.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
from utcp.utcp_client import UtcpClient
1717
import logging
1818

19-
logger = logging.getLogger(__name__)
20-
21-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
22-
handler = logging.StreamHandler(sys.stderr)
23-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
24-
logger.addHandler(handler)
25-
logger.setLevel(logging.INFO)
19+
logging.basicConfig(
20+
level=logging.INFO,
21+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
22+
)
2623

24+
logger = logging.getLogger(__name__)
2725

2826
class McpCommunicationProtocol(CommunicationProtocol):
2927
"""REQUIRED

plugins/communication_protocols/socket/src/utcp_socket/tcp_communication_protocol.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
from utcp.shared.tool import Tool
1616
import logging
1717

18-
logger = logging.getLogger(__name__)
18+
logging.basicConfig(
19+
level=logging.INFO,
20+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
21+
)
1922

20-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
21-
handler = logging.StreamHandler(sys.stderr)
22-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
23-
logger.addHandler(handler)
24-
logger.setLevel(logging.INFO)
23+
logger = logging.getLogger(__name__)
2524

2625
class TCPTransport(ClientTransportInterface):
2726
"""Transport implementation for TCP-based tool providers.

plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424

2525
import logging
2626

27-
logger = logging.getLogger(__name__)
28-
29-
if not logger.hasHandlers(): # Only add default handler if user didn't configure logging
30-
handler = logging.StreamHandler(sys.stderr)
31-
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"))
32-
logger.addHandler(handler)
33-
logger.setLevel(logging.INFO)
27+
logging.basicConfig(
28+
level=logging.INFO,
29+
format="%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s"
30+
)
3431

32+
logger = logging.getLogger(__name__)
3533

3634
class TextCommunicationProtocol(CommunicationProtocol):
3735
"""REQUIRED

0 commit comments

Comments
 (0)