feat: improve debug message handling with better truncation and formatting

This commit is contained in:
yangdx
2025-02-21 16:28:08 +08:00
parent 2d8a262ac3
commit c95656ca87
2 changed files with 18 additions and 4 deletions

View File

@@ -538,9 +538,7 @@ async def extract_entities(
verbose_debug( verbose_debug(
f"New entities:{all_entities_data}, relationships:{all_relationships_data}" f"New entities:{all_entities_data}, relationships:{all_relationships_data}"
) )
verbose_debug( verbose_debug(f"New relationships:{all_relationships_data}")
f"New relationships:{all_relationships_data}"
)
if entity_vdb is not None: if entity_vdb is not None:
data_for_vdb = { data_for_vdb = {

View File

@@ -25,10 +25,26 @@ VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
def verbose_debug(msg: str, *args, **kwargs): def verbose_debug(msg: str, *args, **kwargs):
"""Function for outputting detailed debug information. """Function for outputting detailed debug information.
When VERBOSE_DEBUG=True, outputs the complete message. When VERBOSE_DEBUG=True, outputs the complete message.
When VERBOSE_DEBUG=False, outputs only the first 30 characters. When VERBOSE_DEBUG=False, outputs only the first 50 characters.
Args:
msg: The message format string
*args: Arguments to be formatted into the message
**kwargs: Keyword arguments passed to logger.debug()
""" """
if VERBOSE_DEBUG: if VERBOSE_DEBUG:
logger.debug(msg, *args, **kwargs) logger.debug(msg, *args, **kwargs)
else:
# Format the message with args first
if args:
formatted_msg = msg % args
else:
formatted_msg = msg
# Then truncate the formatted message
truncated_msg = (
formatted_msg[:50] + "..." if len(formatted_msg) > 50 else formatted_msg
)
logger.debug(truncated_msg, **kwargs)
def set_verbose_debug(enabled: bool): def set_verbose_debug(enabled: bool):