yangdx commited on
Commit
494431b
·
1 Parent(s): 677b7b9

feat: improve debug message handling with better truncation and formatting

Browse files
Files changed (2) hide show
  1. lightrag/operate.py +1 -3
  2. lightrag/utils.py +17 -1
lightrag/operate.py CHANGED
@@ -538,9 +538,7 @@ async def extract_entities(
538
  verbose_debug(
539
  f"New entities:{all_entities_data}, relationships:{all_relationships_data}"
540
  )
541
- verbose_debug(
542
- f"New relationships:{all_relationships_data}"
543
- )
544
 
545
  if entity_vdb is not None:
546
  data_for_vdb = {
 
538
  verbose_debug(
539
  f"New entities:{all_entities_data}, relationships:{all_relationships_data}"
540
  )
541
+ verbose_debug(f"New relationships:{all_relationships_data}")
 
 
542
 
543
  if entity_vdb is not None:
544
  data_for_vdb = {
lightrag/utils.py CHANGED
@@ -25,10 +25,26 @@ VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
25
  def verbose_debug(msg: str, *args, **kwargs):
26
  """Function for outputting detailed debug information.
27
  When VERBOSE_DEBUG=True, outputs the complete message.
28
- When VERBOSE_DEBUG=False, outputs only the first 30 characters.
 
 
 
 
 
29
  """
30
  if VERBOSE_DEBUG:
31
  logger.debug(msg, *args, **kwargs)
 
 
 
 
 
 
 
 
 
 
 
32
 
33
 
34
  def set_verbose_debug(enabled: bool):
 
25
  def verbose_debug(msg: str, *args, **kwargs):
26
  """Function for outputting detailed debug information.
27
  When VERBOSE_DEBUG=True, outputs the complete message.
28
+ When VERBOSE_DEBUG=False, outputs only the first 50 characters.
29
+
30
+ Args:
31
+ msg: The message format string
32
+ *args: Arguments to be formatted into the message
33
+ **kwargs: Keyword arguments passed to logger.debug()
34
  """
35
  if VERBOSE_DEBUG:
36
  logger.debug(msg, *args, **kwargs)
37
+ else:
38
+ # Format the message with args first
39
+ if args:
40
+ formatted_msg = msg % args
41
+ else:
42
+ formatted_msg = msg
43
+ # Then truncate the formatted message
44
+ truncated_msg = (
45
+ formatted_msg[:50] + "..." if len(formatted_msg) > 50 else formatted_msg
46
+ )
47
+ logger.debug(truncated_msg, **kwargs)
48
 
49
 
50
  def set_verbose_debug(enabled: bool):