m7mdal7aj commited on
Commit
a0d48c1
1 Parent(s): b97c9f9

Update my_model/utilities/gen_utilities.py

Browse files
Files changed (1) hide show
  1. my_model/utilities/gen_utilities.py +13 -6
my_model/utilities/gen_utilities.py CHANGED
@@ -12,30 +12,35 @@ import logging
12
  import functools
13
 
14
 
 
 
 
 
 
 
15
 
16
  # Set up logging
17
- logging.basicConfig(filename='my_model/utilities/app.log', level=logging.INFO, format='%(asctime)s - %(message)s')
18
 
19
  def log_event(event: str) -> None:
20
  """
21
  Logs an event with the current timestamp.
22
-
23
  Args:
24
  event (str): The event description to log.
25
  """
26
- logging.info(event)
 
 
 
27
 
28
  def log_function_call(func):
29
  """
30
  Decorator that logs the function call details (name and arguments).
31
-
32
  Args:
33
  func (function): The function to be decorated.
34
-
35
  Returns:
36
  function: The wrapped function with logging.
37
  """
38
- st.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
39
  @functools.wraps(func)
40
  def wrapper(*args, **kwargs):
41
  log_event(f'Function {func.__name__} called with args: {args} and kwargs: {kwargs}')
@@ -44,6 +49,8 @@ def log_function_call(func):
44
  return result
45
  return wrapper
46
 
 
 
47
 
48
  def show_image(image):
49
  """
 
12
  import functools
13
 
14
 
15
+ ###### this is used for logging any interaction with the app. ########
16
+
17
+ ###### Logging Decorator ########
18
+ log_dir = 'my_model/utilities'
19
+ if not os.path.exists(log_dir):
20
+ os.makedirs(log_dir)
21
 
22
  # Set up logging
23
+ logging.basicConfig(filename=os.path.join(log_dir, 'app.log'), level=logging.DEBUG, format='%(asctime)s - %(message)s')
24
 
25
  def log_event(event: str) -> None:
26
  """
27
  Logs an event with the current timestamp.
 
28
  Args:
29
  event (str): The event description to log.
30
  """
31
+ try:
32
+ logging.info(event)
33
+ except Exception as e:
34
+ logging.error(f"Failed to log event: {e}")
35
 
36
  def log_function_call(func):
37
  """
38
  Decorator that logs the function call details (name and arguments).
 
39
  Args:
40
  func (function): The function to be decorated.
 
41
  Returns:
42
  function: The wrapped function with logging.
43
  """
 
44
  @functools.wraps(func)
45
  def wrapper(*args, **kwargs):
46
  log_event(f'Function {func.__name__} called with args: {args} and kwargs: {kwargs}')
 
49
  return result
50
  return wrapper
51
 
52
+ ##### End of Logging Decorator #####
53
+
54
 
55
  def show_image(image):
56
  """