Niansuh commited on
Commit
1990d11
·
verified ·
1 Parent(s): 18f26ab

Update api/logger.py

Browse files
Files changed (1) hide show
  1. api/logger.py +5 -5
api/logger.py CHANGED
@@ -2,11 +2,11 @@ import logging
2
 
3
  class ChatIDLoggerAdapter(logging.LoggerAdapter):
4
  def process(self, msg, kwargs):
5
- # Include the chat_id in the log message if provided
6
- chat_id = self.extra.get('chat_id', 'N/A')
7
  return f"[Chat ID: {chat_id}] {msg}", kwargs
8
 
9
- def setup_logger(name, chat_id=None):
10
  logger = logging.getLogger(name)
11
  if not logger.handlers:
12
  logger.setLevel(logging.INFO)
@@ -17,5 +17,5 @@ def setup_logger(name, chat_id=None):
17
  console_handler.setFormatter(formatter)
18
  logger.addHandler(console_handler)
19
 
20
- # Ensure we return a LoggerAdapter with or without chat_id
21
- return ChatIDLoggerAdapter(logger, {'chat_id': chat_id})
 
2
 
3
  class ChatIDLoggerAdapter(logging.LoggerAdapter):
4
  def process(self, msg, kwargs):
5
+ # Check if 'chat_id' is passed in kwargs; otherwise, use 'N/A'
6
+ chat_id = kwargs.pop('chat_id', 'N/A')
7
  return f"[Chat ID: {chat_id}] {msg}", kwargs
8
 
9
+ def setup_logger(name):
10
  logger = logging.getLogger(name)
11
  if not logger.handlers:
12
  logger.setLevel(logging.INFO)
 
17
  console_handler.setFormatter(formatter)
18
  logger.addHandler(console_handler)
19
 
20
+ # Return the LoggerAdapter without a fixed chat_id
21
+ return ChatIDLoggerAdapter(logger, {})