maleo-foundation 0.0.40__py3-none-any.whl → 0.0.42__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.
@@ -0,0 +1,33 @@
1
+ from typing import Dict
2
+ from maleo_foundation.enums import BaseEnums
3
+ from maleo_foundation.types import BaseTypes
4
+ from maleo_foundation.utils.logger import BaseLogger
5
+
6
+ class ClientLoggingManager:
7
+ _loggers:Dict[type, BaseLogger] = {}
8
+
9
+ @classmethod
10
+ def initialize(
11
+ cls,
12
+ base_dir:str,
13
+ client_name:str,
14
+ service_name:BaseTypes.OptionalString = None,
15
+ level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
16
+ ) -> BaseLogger:
17
+ """Initialize client logger if not already initialized."""
18
+ if cls not in cls._loggers:
19
+ cls._loggers[cls] = BaseLogger(
20
+ base_dir=base_dir,
21
+ type=BaseEnums.LoggerType.CLIENT,
22
+ service_name=service_name,
23
+ client_name=client_name,
24
+ level=level
25
+ )
26
+ return cls._loggers[cls]
27
+
28
+ @classmethod
29
+ def get(cls) -> BaseLogger:
30
+ """Return client logger (if exist) or raise Runtime Error"""
31
+ if cls not in cls._loggers:
32
+ raise RuntimeError("Logger has not been initialized. Call 'initialize' first.")
33
+ return cls._loggers[cls]
@@ -9,7 +9,7 @@ class BaseLogger(logging.Logger):
9
9
  def __init__(
10
10
  self,
11
11
  base_dir:str,
12
- type:BaseEnums.LoggerType = BaseEnums.LoggerType.APPLICATION,
12
+ type:BaseEnums.LoggerType,
13
13
  service_name:BaseTypes.OptionalString = None,
14
14
  client_name:BaseTypes.OptionalString = None,
15
15
  level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
@@ -62,12 +62,16 @@ class BaseLogger(logging.Logger):
62
62
  self.warning(f"Failed to initialize Google Cloud Logging: {str(e)}")
63
63
 
64
64
  #* Define log directory
65
- log_dir = os.path.join(base_dir, f"logs/{type}")
66
- os.makedirs(log_dir, exist_ok=True)
65
+ if type == BaseEnums.LoggerType.CLIENT:
66
+ log_dir = f"logs/{type}/{client_name}"
67
+ else:
68
+ log_dir = f"logs/{type}"
69
+ full_log_dir = os.path.join(base_dir, log_dir)
70
+ os.makedirs(full_log_dir, exist_ok=True)
67
71
 
68
72
  #* Generate timestamped filename
69
73
  timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
70
- log_filename = os.path.join(log_dir, f"{timestamp}.log")
74
+ log_filename = os.path.join(full_log_dir, f"{timestamp}.log")
71
75
 
72
76
  #* File handler
73
77
  file_handler = logging.FileHandler(log_filename, mode="a")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.0.40
3
+ Version: 0.0.42
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -6,6 +6,7 @@ maleo_foundation/extended_types.py,sha256=pIKt-_9tby4rmune3fmWcCW_mohaNRh_1lywBm
6
6
  maleo_foundation/query.py,sha256=qJV9-QX5bphsmijXf4I8cuwMnqlJkm0dxypJ9Qz1eS8,3850
7
7
  maleo_foundation/types.py,sha256=D_EtYK-sNeELSbc-ngX65iuQCRhZQB4TtV73P6Gl76o,1206
8
8
  maleo_foundation/clients/__init__.py,sha256=W8vydJYeDEi6gdmOZSBFSSDsfZJtb8C05CHErZgsZ30,188
9
+ maleo_foundation/clients/logging.py,sha256=JaAYfLkci97bTb6Wt5YO1uxQK5afIMuR8kin0q5rlIM,1145
9
10
  maleo_foundation/clients/general/__init__.py,sha256=l9eQrBeLW4aXtGU5aK3i6fD-msVR4526W7D9V8WCXIg,91
10
11
  maleo_foundation/clients/general/http.py,sha256=Awvs470hgdhZSZW_uoIFJGcJ5hcfDEIX0A2yUaP9UCA,1353
11
12
  maleo_foundation/clients/google/__init__.py,sha256=1uv6nF9QbATsSAcMimQOT7Y-eBljjDunBojNX6oAtS8,90
@@ -47,10 +48,10 @@ maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256
47
48
  maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
48
49
  maleo_foundation/utils/__init__.py,sha256=tfgaHZI2PDgxEVSQztfnDMN5S6L5Y4FcK5v_Wkf5snE,245
49
50
  maleo_foundation/utils/exceptions.py,sha256=mcvBwHm6uWpVQkPtO1T2j-GaTYEiyPOeGxiDL9-sjNA,3639
50
- maleo_foundation/utils/logger.py,sha256=hnUAgXDMcNO-oF9jtxbWPKxb9BR9yVofwLrEiGp2mgk,3215
51
+ maleo_foundation/utils/logger.py,sha256=sK95UC5jLKKuAV8lu8pFnoQfLRB0nPtCbmAC5CJLgO8,3338
51
52
  maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
52
53
  maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
53
- maleo_foundation-0.0.40.dist-info/METADATA,sha256=GrdXX9GQwWrFLylpWMKrbqIZ8VdziY1Et4-mrEH01CQ,3160
54
- maleo_foundation-0.0.40.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
55
- maleo_foundation-0.0.40.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
56
- maleo_foundation-0.0.40.dist-info/RECORD,,
54
+ maleo_foundation-0.0.42.dist-info/METADATA,sha256=m-q9ERS9TmHNFqh_G21F3p2DpoAisXytaSGBBh5nmC0,3160
55
+ maleo_foundation-0.0.42.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
56
+ maleo_foundation-0.0.42.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
57
+ maleo_foundation-0.0.42.dist-info/RECORD,,