Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit cf1ac0f

Browse files
author
Luke Hinds
committed
Make weaviate conform with codegate logging
1 parent 00a0c96 commit cf1ac0f

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/codegate/storage/storage_engine.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from weaviate.classes.query import MetadataQuery
55
from weaviate.embedded import EmbeddedOptions
66

7+
from codegate.config import Config
78
from codegate.inference.inference_engine import LlamaCppInferenceEngine
89

910
logger = structlog.get_logger("codegate")
@@ -24,8 +25,32 @@
2425
class StorageEngine:
2526
def get_client(self, data_path):
2627
try:
28+
# Get current config
29+
config = Config.get_config()
30+
31+
# Configure Weaviate logging
32+
additional_env_vars = {
33+
# Basic logging configuration
34+
"LOG_FORMAT": config.log_format.value.lower(),
35+
"LOG_LEVEL": config.log_level.value.lower(),
36+
# Disable colored output
37+
"LOG_FORCE_COLOR": "false",
38+
# Configure JSON format
39+
"LOG_JSON_FIELDS": "timestamp, level,message",
40+
# Configure text format
41+
"LOG_METHOD": config.log_format.value.lower(),
42+
"LOG_LEVEL_IN_UPPER": "false", # Keep level lowercase like codegate format
43+
# Disable additional fields
44+
"LOG_GIT_HASH": "false",
45+
"LOG_VERSION": "false",
46+
"LOG_BUILD_INFO": "false",
47+
}
48+
2749
client = weaviate.WeaviateClient(
28-
embedded_options=EmbeddedOptions(persistence_data_path=data_path),
50+
embedded_options=EmbeddedOptions(
51+
persistence_data_path=data_path,
52+
additional_env_vars=additional_env_vars,
53+
),
2954
)
3055
return client
3156
except Exception as e:
@@ -50,7 +75,7 @@ def __init__(self, data_path="./weaviate_data"):
5075
try:
5176
weaviate_client.close()
5277
except Exception as e:
53-
logger.info(f"Failed to close client: {str(e)}")
78+
logger.error(f"Failed to close client: {str(e)}")
5479
else:
5580
logger.error("Could not find client, skipping schema setup.")
5681

@@ -60,7 +85,7 @@ def setup_schema(self, client):
6085
client.collections.create(
6186
class_config["name"], properties=class_config["properties"]
6287
)
63-
logger.info(f"Weaviate schema for class {class_config['name']} setup complete.")
88+
logger.info(f"Weaviate schema for class {class_config['name']} setup complete.")
6489

6590
async def search(self, query: str, limit=5, distance=0.3) -> list[object]:
6691
"""
@@ -104,4 +129,4 @@ async def search(self, query: str, limit=5, distance=0.3) -> list[object]:
104129
try:
105130
weaviate_client.close()
106131
except Exception as e:
107-
logger.info(f"Failed to close client: {str(e)}")
132+
logger.error(f"Failed to close client: {str(e)}")

tests/test_storage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def mock_inference_engine():
3535
@pytest.mark.asyncio
3636
async def test_search(mock_weaviate_client, mock_inference_engine):
3737
# Patch the LlamaCppInferenceEngine.embed method (not the entire class)
38-
with patch("codegate.inference.inference_engine.LlamaCppInferenceEngine.embed",
39-
mock_inference_engine.embed):
38+
with patch(
39+
"codegate.inference.inference_engine.LlamaCppInferenceEngine.embed",
40+
mock_inference_engine.embed,
41+
):
4042

4143
# Mock the WeaviateClient as before
4244
with patch("weaviate.WeaviateClient", return_value=mock_weaviate_client):

0 commit comments

Comments
 (0)