mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 20:51:02 +02:00
Logging strategy updates
This commit is contained in:
parent
1359eb8a3d
commit
d91a82d8d5
5 changed files with 33 additions and 14 deletions
|
|
@ -1,7 +1,11 @@
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from . exceptions import *
|
from . exceptions import *
|
||||||
from . types import ConfigValue
|
from . types import ConfigValue
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
def __init__(self, api):
|
def __init__(self, api):
|
||||||
|
|
@ -33,7 +37,7 @@ class Config:
|
||||||
for v in object["values"]
|
for v in object["values"]
|
||||||
]
|
]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
logger.error("Failed to parse config get response", exc_info=True)
|
||||||
raise ProtocolException("Response not formatted correctly")
|
raise ProtocolException("Response not formatted correctly")
|
||||||
|
|
||||||
def put(self, values):
|
def put(self, values):
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,14 @@
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import base64
|
import base64
|
||||||
|
import logging
|
||||||
|
|
||||||
from . types import DocumentMetadata, ProcessingMetadata, Triple
|
from . types import DocumentMetadata, ProcessingMetadata, Triple
|
||||||
from .. knowledge import hash, Uri, Literal
|
from .. knowledge import hash, Uri, Literal
|
||||||
from . exceptions import *
|
from . exceptions import *
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def to_value(x):
|
def to_value(x):
|
||||||
if x["e"]: return Uri(x["v"])
|
if x["e"]: return Uri(x["v"])
|
||||||
return Literal(x["v"])
|
return Literal(x["v"])
|
||||||
|
|
@ -112,7 +115,7 @@ class Library:
|
||||||
for v in object["document-metadatas"]
|
for v in object["document-metadatas"]
|
||||||
]
|
]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
logger.error("Failed to parse document list response", exc_info=True)
|
||||||
raise ProtocolException(f"Response not formatted correctly")
|
raise ProtocolException(f"Response not formatted correctly")
|
||||||
|
|
||||||
def get_document(self, user, id):
|
def get_document(self, user, id):
|
||||||
|
|
@ -145,7 +148,7 @@ class Library:
|
||||||
tags = doc["tags"]
|
tags = doc["tags"]
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
logger.error("Failed to parse document response", exc_info=True)
|
||||||
raise ProtocolException(f"Response not formatted correctly")
|
raise ProtocolException(f"Response not formatted correctly")
|
||||||
|
|
||||||
def update_document(self, user, id, metadata):
|
def update_document(self, user, id, metadata):
|
||||||
|
|
@ -192,7 +195,7 @@ class Library:
|
||||||
tags = doc["tags"]
|
tags = doc["tags"]
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
logger.error("Failed to parse document update response", exc_info=True)
|
||||||
raise ProtocolException(f"Response not formatted correctly")
|
raise ProtocolException(f"Response not formatted correctly")
|
||||||
|
|
||||||
def remove_document(self, user, id):
|
def remove_document(self, user, id):
|
||||||
|
|
@ -266,6 +269,6 @@ class Library:
|
||||||
for v in object["processing-metadatas"]
|
for v in object["processing-metadatas"]
|
||||||
]
|
]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
logger.error("Failed to parse processing list response", exc_info=True)
|
||||||
raise ProtocolException(f"Response not formatted correctly")
|
raise ProtocolException(f"Response not formatted correctly")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
|
|
||||||
from pulsar.schema import JsonSchema
|
from pulsar.schema import JsonSchema
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# Module logger
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Producer:
|
class Producer:
|
||||||
|
|
||||||
|
|
@ -39,15 +43,15 @@ class Producer:
|
||||||
while self.running and self.producer is None:
|
while self.running and self.producer is None:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("Connect publisher to", self.topic, "...", flush=True)
|
logger.info(f"Connecting publisher to {self.topic}...")
|
||||||
self.producer = self.client.create_producer(
|
self.producer = self.client.create_producer(
|
||||||
topic = self.topic,
|
topic = self.topic,
|
||||||
schema = JsonSchema(self.schema),
|
schema = JsonSchema(self.schema),
|
||||||
chunking_enabled = self.chunking_enabled,
|
chunking_enabled = self.chunking_enabled,
|
||||||
)
|
)
|
||||||
print("Connected to", self.topic, flush=True)
|
logger.info(f"Connected publisher to {self.topic}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception:", e, flush=True)
|
logger.error(f"Exception connecting publisher: {e}", exc_info=True)
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
if not self.running: break
|
if not self.running: break
|
||||||
|
|
@ -68,7 +72,7 @@ class Producer:
|
||||||
break
|
break
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception:", e, flush=True)
|
logger.error(f"Exception sending message: {e}", exc_info=True)
|
||||||
self.producer.close()
|
self.producer.close()
|
||||||
self.producer = None
|
self.producer = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@ from pulsar.schema import JsonSchema
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
import pulsar
|
import pulsar
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# Module logger
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Publisher:
|
class Publisher:
|
||||||
|
|
||||||
|
|
@ -62,7 +66,7 @@ class Publisher:
|
||||||
producer.send(item)
|
producer.send(item)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception:", e, flush=True)
|
logger.error(f"Exception in publisher: {e}", exc_info=True)
|
||||||
|
|
||||||
if not self.running:
|
if not self.running:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
from . subscriber import Subscriber
|
from . subscriber import Subscriber
|
||||||
from . producer import Producer
|
from . producer import Producer
|
||||||
from . spec import Spec
|
from . spec import Spec
|
||||||
from . metrics import ConsumerMetrics, ProducerMetrics, SubscriberMetrics
|
from . metrics import ConsumerMetrics, ProducerMetrics, SubscriberMetrics
|
||||||
|
|
||||||
|
# Module logger
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class RequestResponse(Subscriber):
|
class RequestResponse(Subscriber):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -45,7 +49,7 @@ class RequestResponse(Subscriber):
|
||||||
|
|
||||||
id = str(uuid.uuid4())
|
id = str(uuid.uuid4())
|
||||||
|
|
||||||
print("Request", id, "...", flush=True)
|
logger.debug(f"Sending request {id}...")
|
||||||
|
|
||||||
q = await self.subscribe(id)
|
q = await self.subscribe(id)
|
||||||
|
|
||||||
|
|
@ -58,7 +62,7 @@ class RequestResponse(Subscriber):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
print("Exception:", e)
|
logger.error(f"Exception sending request: {e}", exc_info=True)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -71,7 +75,7 @@ class RequestResponse(Subscriber):
|
||||||
timeout=timeout
|
timeout=timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Got response.", flush=True)
|
logger.debug("Received response")
|
||||||
|
|
||||||
if recipient is None:
|
if recipient is None:
|
||||||
|
|
||||||
|
|
@ -93,7 +97,7 @@ class RequestResponse(Subscriber):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
print("Exception:", e)
|
logger.error(f"Exception processing response: {e}", exc_info=True)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue