Niansuh commited on
Commit
3bd47a9
·
verified ·
1 Parent(s): 1a5834c

Update api/logger.py

Browse files
Files changed (1) hide show
  1. api/logger.py +24 -8
api/logger.py CHANGED
@@ -1,5 +1,6 @@
1
  import logging
2
 
 
3
  def setup_logger(name):
4
  logger = logging.getLogger(name)
5
  if not logger.handlers:
@@ -21,18 +22,33 @@ def setup_logger(name):
21
 
22
  logger = setup_logger(__name__)
23
 
24
- # New functions for logging different scenarios
25
- def log_generated_chat_id(chat_id, chat_url):
26
- logger.info(f"Generated Chat ID: {chat_id} - URL: {chat_url}")
 
 
 
27
 
28
- def log_model_delay(delay_seconds, chat_id, model):
 
 
 
29
  logger.info(f"Introducing a delay of {delay_seconds} seconds for model '{model}' (Chat ID: {chat_id})")
30
 
31
- def log_http_error(chat_id, error):
 
 
 
32
  logger.error(f"HTTP error occurred for Chat ID {chat_id}: {error}")
33
 
34
- def log_request_error(chat_id, error):
35
- logger.error(f"Error occurred during request for Chat ID {chat_id}: {error}")
 
 
 
36
 
37
- def log_strip_prefix(model_prefix):
 
 
 
38
  logger.debug(f"Stripping prefix '{model_prefix}' from content.")
 
1
  import logging
2
 
3
+ # Setup logger with a consistent format
4
  def setup_logger(name):
5
  logger = logging.getLogger(name)
6
  if not logger.handlers:
 
22
 
23
  logger = setup_logger(__name__)
24
 
25
+ # Log functions to structure specific logs in utils.py
26
+ def log_generated_chat_id_with_referer(chat_id, model, referer_url):
27
+ """
28
+ Log the generated Chat ID with model and referer URL if it exists.
29
+ """
30
+ logger.info(f"Generated Chat ID: {chat_id} - Model: {model} - URL: {referer_url}")
31
 
32
+ def log_model_delay(delay_seconds, model, chat_id):
33
+ """
34
+ Log the delay introduced for specific models.
35
+ """
36
  logger.info(f"Introducing a delay of {delay_seconds} seconds for model '{model}' (Chat ID: {chat_id})")
37
 
38
+ def log_http_error(error, chat_id):
39
+ """
40
+ Log HTTP errors encountered during requests.
41
+ """
42
  logger.error(f"HTTP error occurred for Chat ID {chat_id}: {error}")
43
 
44
+ def log_request_error(error, chat_id):
45
+ """
46
+ Log request errors unrelated to HTTP status.
47
+ """
48
+ logger.error(f"Request error occurred for Chat ID {chat_id}: {error}")
49
 
50
+ def log_strip_prefix(model_prefix, content):
51
+ """
52
+ Log when a model prefix is stripped from the content.
53
+ """
54
  logger.debug(f"Stripping prefix '{model_prefix}' from content.")