maleo-foundation 0.0.39__py3-none-any.whl → 0.0.41__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
maleo_foundation/enums.py CHANGED
@@ -61,6 +61,12 @@ class BaseEnums:
61
61
  BaseEnums.RESTControllerResponseType.FILE: responses.FileResponse,
62
62
  }.get(self, responses.Response)
63
63
 
64
+ class LoggerType(StrEnum):
65
+ MIDDLEWARE = "middleware"
66
+ DATABASE = "database"
67
+ APPLICATION = "application"
68
+ CLIENT = "client"
69
+
64
70
  class LoggerLevel(IntEnum):
65
71
  CRITICAL = logging.CRITICAL
66
72
  FATAL = logging.FATAL
@@ -3,28 +3,42 @@ import os
3
3
  from datetime import datetime
4
4
  from maleo_foundation.clients.google.cloud.logging import GoogleCloudLogging
5
5
  from maleo_foundation.enums import BaseEnums
6
+ from maleo_foundation.types import BaseTypes
6
7
 
7
8
  class BaseLogger(logging.Logger):
8
9
  def __init__(
9
10
  self,
10
11
  base_dir:str,
11
- service_name:str,
12
- category:str,
12
+ type:BaseEnums.LoggerType,
13
+ service_name:BaseTypes.OptionalString = None,
14
+ client_name:BaseTypes.OptionalString = None,
13
15
  level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
14
16
  ):
15
17
  """
16
18
  Custom extended logger with file, console, and Google Cloud Logging.
17
19
 
18
- - Logs are stored in `base_dir/logs/{category}`
20
+ - Logs are stored in `base_dir/logs/{type}`
19
21
  - Uses Google Cloud Logging if configured
20
22
 
21
23
  Args:
22
24
  base_dir (str): Base directory for logs (e.g., "/path/to/maleo_security")
23
25
  service_name (str): The service name (e.g., "maleo_security")
24
- category (str): Log category (e.g., "application", "middleware")
26
+ type (str): Log type (e.g., "application", "middleware")
25
27
  """
28
+ #* Ensure service_name exists
29
+ service_name = service_name or os.getenv("SERVICE_NAME")
30
+ if service_name is None:
31
+ raise ValueError("SERVICE_NAME environment variable must be set if service_name is set to None")
32
+
33
+ #* Ensure client_name is valid if logger type is a client
34
+ if type == BaseEnums.LoggerType.CLIENT and client_name is None:
35
+ raise ValueError("'client_name' parameter must be provided if 'logger_type' is 'client'")
36
+
26
37
  #* Define logger name
27
- name = f"{service_name} - {category}"
38
+ if type == BaseEnums.LoggerType.CLIENT:
39
+ name = f"{service_name} - {type} - {client_name}"
40
+ else:
41
+ name = f"{service_name} - {type}"
28
42
  super().__init__(name, level)
29
43
 
30
44
  #* Clear existing handlers to prevent duplicates
@@ -48,7 +62,7 @@ class BaseLogger(logging.Logger):
48
62
  self.warning(f"Failed to initialize Google Cloud Logging: {str(e)}")
49
63
 
50
64
  #* Define log directory
51
- log_dir = os.path.join(base_dir, f"logs/{category}")
65
+ log_dir = os.path.join(base_dir, f"logs/{type}")
52
66
  os.makedirs(log_dir, exist_ok=True)
53
67
 
54
68
  #* Generate timestamped filename
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.0.39
3
+ Version: 0.0.41
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
1
  maleo_foundation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  maleo_foundation/constants.py,sha256=aBmEfWlBqZxi0k-n6h2NM1YRLOjMnheEiLyQcjP-zCQ,1164
3
3
  maleo_foundation/controller.py,sha256=9ceIEajWLouLBph2NQe7L7tQNnQyyW_ETojilSeFv6M,2991
4
- maleo_foundation/enums.py,sha256=skLmbrD7DqL1CJN2BCRfWYu5QU1XZVIa_SoJnZbZcrs,2201
4
+ maleo_foundation/enums.py,sha256=uXA5fLFeDXwlspUjU4DXSB68dfanxEwIJhsAMZXhsYo,2359
5
5
  maleo_foundation/extended_types.py,sha256=pIKt-_9tby4rmune3fmWcCW_mohaNRh_1lywBmdc-L4,301
6
6
  maleo_foundation/query.py,sha256=qJV9-QX5bphsmijXf4I8cuwMnqlJkm0dxypJ9Qz1eS8,3850
7
7
  maleo_foundation/types.py,sha256=D_EtYK-sNeELSbc-ngX65iuQCRhZQB4TtV73P6Gl76o,1206
@@ -47,10 +47,10 @@ maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256
47
47
  maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
48
48
  maleo_foundation/utils/__init__.py,sha256=tfgaHZI2PDgxEVSQztfnDMN5S6L5Y4FcK5v_Wkf5snE,245
49
49
  maleo_foundation/utils/exceptions.py,sha256=mcvBwHm6uWpVQkPtO1T2j-GaTYEiyPOeGxiDL9-sjNA,3639
50
- maleo_foundation/utils/logger.py,sha256=S9YtXy6AO7qP1vkcPXqnzPbgCIoTfr2DZGCT9vuA1_Q,2446
50
+ maleo_foundation/utils/logger.py,sha256=rfViHIMN6p9LeyH_fU_PiWvGuhHcivgk9zRQuXyw6ik,3180
51
51
  maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
52
52
  maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
53
- maleo_foundation-0.0.39.dist-info/METADATA,sha256=cfFp2YRumuQ4SP57WT9KwQxY0BYXaCdO0hdf9KCMel0,3160
54
- maleo_foundation-0.0.39.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
55
- maleo_foundation-0.0.39.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
56
- maleo_foundation-0.0.39.dist-info/RECORD,,
53
+ maleo_foundation-0.0.41.dist-info/METADATA,sha256=sMX6yNYfAGGFalLxQj-MmV82Vesp_HPGa6fX7EZnCcA,3160
54
+ maleo_foundation-0.0.41.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
55
+ maleo_foundation-0.0.41.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
56
+ maleo_foundation-0.0.41.dist-info/RECORD,,