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

Commit 23fe594

Browse files
author
Luke Hinds
authored
Merge pull request #174 from stacklok/weaviate-logging
Make weaviate conform with codegate logging
2 parents 3af0175 + cf1ac0f commit 23fe594

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
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)}")

0 commit comments

Comments
 (0)