maleo-logging 0.0.5__py3-none-any.whl → 0.0.7__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/logging/config.py +31 -0
- maleo/logging/logger.py +171 -297
- {maleo_logging-0.0.5.dist-info → maleo_logging-0.0.7.dist-info}/METADATA +2 -2
- maleo_logging-0.0.7.dist-info/RECORD +10 -0
- maleo/logging/dtos.py +0 -24
- maleo_logging-0.0.5.dist-info/RECORD +0 -10
- {maleo_logging-0.0.5.dist-info → maleo_logging-0.0.7.dist-info}/WHEEL +0 -0
- {maleo_logging-0.0.5.dist-info → maleo_logging-0.0.7.dist-info}/licenses/LICENSE +0 -0
- {maleo_logging-0.0.5.dist-info → maleo_logging-0.0.7.dist-info}/top_level.txt +0 -0
maleo/logging/config.py
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
2
|
+
from typing import Optional, Self
|
3
|
+
from maleo.types.base.dict import OptionalStringToStringDict
|
4
|
+
from maleo.types.base.string import OptionalString
|
5
|
+
from .enums import Level
|
6
|
+
from .google import GoogleCloudLogging
|
7
|
+
|
8
|
+
|
9
|
+
class Config(BaseModel):
|
10
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
11
|
+
|
12
|
+
dir: str = Field(..., description="Log's directory")
|
13
|
+
level: Level = Field(Level.INFO, description="Log's level")
|
14
|
+
google_cloud_logging: Optional[GoogleCloudLogging] = Field(
|
15
|
+
default_factory=GoogleCloudLogging, description="Google cloud logging"
|
16
|
+
)
|
17
|
+
labels: OptionalStringToStringDict = Field(
|
18
|
+
None, description="Log labels. (Optional)"
|
19
|
+
)
|
20
|
+
aggregate_file_name: OptionalString = Field(
|
21
|
+
None, description="Log aggregate file name"
|
22
|
+
)
|
23
|
+
individual_log: bool = Field(True, description="Whether to have individual log")
|
24
|
+
|
25
|
+
@model_validator(mode="after")
|
26
|
+
def validate_aggregate_file_name(self) -> Self:
|
27
|
+
if isinstance(self.aggregate_file_name, str):
|
28
|
+
if not self.aggregate_file_name.endswith(".log"):
|
29
|
+
self.aggregate_file_name += ".log"
|
30
|
+
|
31
|
+
return self
|
maleo/logging/logger.py
CHANGED
@@ -1,31 +1,27 @@
|
|
1
1
|
import logging
|
2
2
|
import os
|
3
3
|
from datetime import datetime, timezone
|
4
|
+
from pydantic import BaseModel, ConfigDict, Field
|
4
5
|
from typing import Literal, Optional, Union, overload
|
5
6
|
from maleo.enums.environment import Environment
|
6
7
|
from maleo.enums.service import Key
|
7
|
-
from maleo.types.base.dict import
|
8
|
+
from maleo.types.base.dict import StringToStringDict
|
8
9
|
from maleo.types.base.string import OptionalString
|
9
|
-
from .
|
10
|
-
from
|
11
|
-
from .enums import Level, LoggerType
|
12
|
-
from .google import GoogleCloudLogging
|
10
|
+
from .config import Config
|
11
|
+
from .enums import LoggerType
|
13
12
|
|
14
13
|
|
14
|
+
# * We suggest to NOT use this class
|
15
|
+
# * Instead use the inherited classes
|
15
16
|
class Base(logging.Logger):
|
16
17
|
def __init__(
|
17
18
|
self,
|
18
|
-
type: LoggerType,
|
19
|
-
dir: str,
|
19
|
+
type: LoggerType = LoggerType.BASE,
|
20
20
|
*,
|
21
21
|
environment: Optional[Environment] = None,
|
22
22
|
service_key: Optional[Key] = None,
|
23
23
|
client_key: OptionalString = None,
|
24
|
-
|
25
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
26
|
-
labels: OptionalStringToStringDict = None,
|
27
|
-
aggregate_file_name: OptionalString = None,
|
28
|
-
inidividual_log: bool = True,
|
24
|
+
config: Config,
|
29
25
|
):
|
30
26
|
self._type = type # Declare logger type
|
31
27
|
|
@@ -63,14 +59,19 @@ class Base(logging.Logger):
|
|
63
59
|
self._name = base_name
|
64
60
|
|
65
61
|
# Define log labels
|
66
|
-
self._labels =
|
67
|
-
logger_type
|
68
|
-
service_environment
|
69
|
-
service_key
|
70
|
-
|
71
|
-
|
62
|
+
self._labels: StringToStringDict = {
|
63
|
+
"logger_type": self._type.value,
|
64
|
+
"service_environment": self._environment.value,
|
65
|
+
"service_key": self._service_key.value,
|
66
|
+
}
|
67
|
+
if client_key is not None:
|
68
|
+
self._labels["client_key"] = client_key
|
69
|
+
if config.labels is not None:
|
70
|
+
self._labels.update(config.labels)
|
71
|
+
|
72
|
+
self._config = config
|
72
73
|
|
73
|
-
super().__init__(self._name, level) # Init the superclass's logger
|
74
|
+
super().__init__(self._name, self._config.level) # Init the superclass's logger
|
74
75
|
|
75
76
|
# Clear existing handlers to prevent duplicates
|
76
77
|
for handler in list(self.handlers):
|
@@ -85,13 +86,10 @@ class Base(logging.Logger):
|
|
85
86
|
self.addHandler(console_handler)
|
86
87
|
|
87
88
|
# Google Cloud Logging handler (If enabled)
|
88
|
-
if google_cloud_logging is not None:
|
89
|
-
|
90
|
-
if labels is not None:
|
91
|
-
final_labels = merge_dicts(final_labels, labels)
|
92
|
-
cloud_logging_handler = google_cloud_logging.create_handler(
|
89
|
+
if self._config.google_cloud_logging is not None:
|
90
|
+
cloud_logging_handler = self._config.google_cloud_logging.create_handler(
|
93
91
|
name=self._name.replace(" ", ""),
|
94
|
-
labels=
|
92
|
+
labels=self._labels,
|
95
93
|
)
|
96
94
|
self.addHandler(cloud_logging_handler)
|
97
95
|
else:
|
@@ -100,10 +98,14 @@ class Base(logging.Logger):
|
|
100
98
|
)
|
101
99
|
|
102
100
|
# Define aggregate log directory
|
103
|
-
if aggregate_file_name is not None:
|
104
|
-
|
105
|
-
|
106
|
-
|
101
|
+
if self._config.aggregate_file_name is not None:
|
102
|
+
aggregate_log_dir = os.path.join(self._log_dir, "aggregate")
|
103
|
+
os.makedirs(aggregate_log_dir, exist_ok=True)
|
104
|
+
if not self._config.aggregate_file_name.endswith(".log"):
|
105
|
+
self._config.aggregate_file_name += ".log"
|
106
|
+
log_filename = os.path.join(
|
107
|
+
aggregate_log_dir, self._config.aggregate_file_name
|
108
|
+
)
|
107
109
|
|
108
110
|
# File handler
|
109
111
|
file_handler = logging.FileHandler(log_filename, mode="a")
|
@@ -114,13 +116,13 @@ class Base(logging.Logger):
|
|
114
116
|
)
|
115
117
|
self.addHandler(file_handler)
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
+
# Define individual log directory
|
120
|
+
if self._config.individual_log:
|
119
121
|
if self._type == LoggerType.CLIENT:
|
120
122
|
log_dir = f"{self._type}/{self._client_key}"
|
121
123
|
else:
|
122
124
|
log_dir = f"{self._type}"
|
123
|
-
self._log_dir = os.path.join(dir, log_dir)
|
125
|
+
self._log_dir = os.path.join(self._config.dir, log_dir)
|
124
126
|
os.makedirs(self._log_dir, exist_ok=True)
|
125
127
|
|
126
128
|
# Generate timestamped filename
|
@@ -138,34 +140,6 @@ class Base(logging.Logger):
|
|
138
140
|
)
|
139
141
|
self.addHandler(file_handler)
|
140
142
|
|
141
|
-
@property
|
142
|
-
def type(self) -> str:
|
143
|
-
return self._type
|
144
|
-
|
145
|
-
@property
|
146
|
-
def location(self) -> str:
|
147
|
-
return self._log_dir
|
148
|
-
|
149
|
-
@property
|
150
|
-
def environment(self) -> Environment:
|
151
|
-
return self._environment
|
152
|
-
|
153
|
-
@property
|
154
|
-
def service(self) -> str:
|
155
|
-
return self._service_key
|
156
|
-
|
157
|
-
@property
|
158
|
-
def client(self) -> OptionalString:
|
159
|
-
return self._client_key
|
160
|
-
|
161
|
-
@property
|
162
|
-
def identity(self) -> str:
|
163
|
-
return self._name
|
164
|
-
|
165
|
-
@property
|
166
|
-
def labels(self) -> Labels:
|
167
|
-
return self._labels
|
168
|
-
|
169
143
|
def dispose(self):
|
170
144
|
"""Dispose of the logger by removing all handlers."""
|
171
145
|
for handler in list(self.handlers):
|
@@ -177,355 +151,237 @@ class Base(logging.Logger):
|
|
177
151
|
class Application(Base):
|
178
152
|
def __init__(
|
179
153
|
self,
|
180
|
-
|
154
|
+
*,
|
181
155
|
environment: Optional[Environment] = None,
|
182
156
|
service_key: Optional[Key] = None,
|
183
|
-
|
184
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
185
|
-
labels: OptionalStringToStringDict = None,
|
186
|
-
aggregate_file_name: OptionalString = None,
|
187
|
-
inidividual_log: bool = True,
|
157
|
+
config: Config,
|
188
158
|
):
|
189
159
|
super().__init__(
|
190
|
-
|
191
|
-
type=LoggerType.APPLICATION,
|
160
|
+
LoggerType.APPLICATION,
|
192
161
|
environment=environment,
|
193
162
|
service_key=service_key,
|
194
163
|
client_key=None,
|
195
|
-
|
196
|
-
google_cloud_logging=google_cloud_logging,
|
197
|
-
labels=labels,
|
198
|
-
aggregate_file_name=aggregate_file_name,
|
199
|
-
inidividual_log=inidividual_log,
|
164
|
+
config=config,
|
200
165
|
)
|
201
166
|
|
202
167
|
|
203
168
|
class Cache(Base):
|
204
169
|
def __init__(
|
205
170
|
self,
|
206
|
-
|
171
|
+
*,
|
207
172
|
environment: Optional[Environment] = None,
|
208
173
|
service_key: Optional[Key] = None,
|
209
|
-
|
210
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
211
|
-
labels: OptionalStringToStringDict = None,
|
212
|
-
aggregate_file_name: OptionalString = None,
|
213
|
-
inidividual_log: bool = True,
|
174
|
+
config: Config,
|
214
175
|
):
|
215
176
|
super().__init__(
|
216
|
-
|
217
|
-
type=LoggerType.CACHE,
|
177
|
+
LoggerType.CACHE,
|
218
178
|
environment=environment,
|
219
179
|
service_key=service_key,
|
220
180
|
client_key=None,
|
221
|
-
|
222
|
-
google_cloud_logging=google_cloud_logging,
|
223
|
-
labels=labels,
|
224
|
-
aggregate_file_name=aggregate_file_name,
|
225
|
-
inidividual_log=inidividual_log,
|
181
|
+
config=config,
|
226
182
|
)
|
227
183
|
|
228
184
|
|
229
185
|
class Client(Base):
|
230
186
|
def __init__(
|
231
187
|
self,
|
232
|
-
|
233
|
-
client_key: str,
|
188
|
+
*,
|
234
189
|
environment: Optional[Environment] = None,
|
235
190
|
service_key: Optional[Key] = None,
|
236
|
-
|
237
|
-
|
238
|
-
labels: OptionalStringToStringDict = None,
|
239
|
-
aggregate_file_name: OptionalString = None,
|
240
|
-
inidividual_log: bool = True,
|
191
|
+
client_key: str,
|
192
|
+
config: Config,
|
241
193
|
):
|
242
194
|
super().__init__(
|
243
|
-
|
244
|
-
type=LoggerType.CLIENT,
|
195
|
+
LoggerType.CACHE,
|
245
196
|
environment=environment,
|
246
197
|
service_key=service_key,
|
247
198
|
client_key=client_key,
|
248
|
-
|
249
|
-
google_cloud_logging=google_cloud_logging,
|
250
|
-
labels=labels,
|
251
|
-
aggregate_file_name=aggregate_file_name,
|
252
|
-
inidividual_log=inidividual_log,
|
199
|
+
config=config,
|
253
200
|
)
|
254
201
|
|
255
202
|
|
256
203
|
class Controller(Base):
|
257
204
|
def __init__(
|
258
205
|
self,
|
259
|
-
|
206
|
+
*,
|
260
207
|
environment: Optional[Environment] = None,
|
261
208
|
service_key: Optional[Key] = None,
|
262
|
-
|
263
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
264
|
-
labels: OptionalStringToStringDict = None,
|
265
|
-
aggregate_file_name: OptionalString = None,
|
266
|
-
inidividual_log: bool = True,
|
209
|
+
config: Config,
|
267
210
|
):
|
268
211
|
super().__init__(
|
269
|
-
|
270
|
-
type=LoggerType.CONTROLLER,
|
212
|
+
LoggerType.CONTROLLER,
|
271
213
|
environment=environment,
|
272
214
|
service_key=service_key,
|
273
215
|
client_key=None,
|
274
|
-
|
275
|
-
google_cloud_logging=google_cloud_logging,
|
276
|
-
labels=labels,
|
277
|
-
aggregate_file_name=aggregate_file_name,
|
278
|
-
inidividual_log=inidividual_log,
|
216
|
+
config=config,
|
279
217
|
)
|
280
218
|
|
281
219
|
|
282
220
|
class Database(Base):
|
283
221
|
def __init__(
|
284
222
|
self,
|
285
|
-
|
223
|
+
*,
|
286
224
|
environment: Optional[Environment] = None,
|
287
225
|
service_key: Optional[Key] = None,
|
288
|
-
|
289
|
-
google_cloud_logging=None,
|
290
|
-
labels: OptionalStringToStringDict = None,
|
291
|
-
aggregate_file_name: OptionalString = None,
|
292
|
-
inidividual_log: bool = True,
|
226
|
+
config: Config,
|
293
227
|
):
|
294
228
|
super().__init__(
|
295
|
-
|
296
|
-
type=LoggerType.DATABASE,
|
229
|
+
LoggerType.DATABASE,
|
297
230
|
environment=environment,
|
298
231
|
service_key=service_key,
|
299
232
|
client_key=None,
|
300
|
-
|
301
|
-
google_cloud_logging=google_cloud_logging,
|
302
|
-
labels=labels,
|
303
|
-
aggregate_file_name=aggregate_file_name,
|
304
|
-
inidividual_log=inidividual_log,
|
233
|
+
config=config,
|
305
234
|
)
|
306
235
|
|
307
236
|
|
308
237
|
class Exception(Base):
|
309
238
|
def __init__(
|
310
239
|
self,
|
311
|
-
|
240
|
+
*,
|
312
241
|
environment: Optional[Environment] = None,
|
313
242
|
service_key: Optional[Key] = None,
|
314
|
-
|
315
|
-
google_cloud_logging=None,
|
316
|
-
labels: OptionalStringToStringDict = None,
|
317
|
-
aggregate_file_name: OptionalString = None,
|
318
|
-
inidividual_log: bool = True,
|
243
|
+
config: Config,
|
319
244
|
):
|
320
245
|
super().__init__(
|
321
|
-
|
322
|
-
type=LoggerType.EXCEPTION,
|
246
|
+
LoggerType.EXCEPTION,
|
323
247
|
environment=environment,
|
324
248
|
service_key=service_key,
|
325
249
|
client_key=None,
|
326
|
-
|
327
|
-
google_cloud_logging=google_cloud_logging,
|
328
|
-
labels=labels,
|
329
|
-
aggregate_file_name=aggregate_file_name,
|
330
|
-
inidividual_log=inidividual_log,
|
250
|
+
config=config,
|
331
251
|
)
|
332
252
|
|
333
253
|
|
334
254
|
class Middleware(Base):
|
335
255
|
def __init__(
|
336
256
|
self,
|
337
|
-
|
257
|
+
*,
|
338
258
|
environment: Optional[Environment] = None,
|
339
259
|
service_key: Optional[Key] = None,
|
340
|
-
|
341
|
-
google_cloud_logging=None,
|
342
|
-
labels: OptionalStringToStringDict = None,
|
343
|
-
aggregate_file_name: OptionalString = None,
|
344
|
-
inidividual_log: bool = True,
|
260
|
+
config: Config,
|
345
261
|
):
|
346
262
|
super().__init__(
|
347
|
-
|
348
|
-
type=LoggerType.MIDDLEWARE,
|
263
|
+
LoggerType.MIDDLEWARE,
|
349
264
|
environment=environment,
|
350
265
|
service_key=service_key,
|
351
266
|
client_key=None,
|
352
|
-
|
353
|
-
google_cloud_logging=google_cloud_logging,
|
354
|
-
labels=labels,
|
355
|
-
aggregate_file_name=aggregate_file_name,
|
356
|
-
inidividual_log=inidividual_log,
|
267
|
+
config=config,
|
357
268
|
)
|
358
269
|
|
359
270
|
|
360
271
|
class Repository(Base):
|
361
272
|
def __init__(
|
362
273
|
self,
|
363
|
-
|
274
|
+
*,
|
364
275
|
environment: Optional[Environment] = None,
|
365
276
|
service_key: Optional[Key] = None,
|
366
|
-
|
367
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
368
|
-
labels: OptionalStringToStringDict = None,
|
369
|
-
aggregate_file_name: OptionalString = None,
|
370
|
-
inidividual_log: bool = True,
|
277
|
+
config: Config,
|
371
278
|
):
|
372
279
|
super().__init__(
|
373
|
-
|
374
|
-
type=LoggerType.REPOSITORY,
|
280
|
+
LoggerType.REPOSITORY,
|
375
281
|
environment=environment,
|
376
282
|
service_key=service_key,
|
377
283
|
client_key=None,
|
378
|
-
|
379
|
-
google_cloud_logging=google_cloud_logging,
|
380
|
-
labels=labels,
|
381
|
-
aggregate_file_name=aggregate_file_name,
|
382
|
-
inidividual_log=inidividual_log,
|
284
|
+
config=config,
|
383
285
|
)
|
384
286
|
|
385
287
|
|
386
288
|
class Service(Base):
|
387
289
|
def __init__(
|
388
290
|
self,
|
389
|
-
|
291
|
+
*,
|
390
292
|
environment: Optional[Environment] = None,
|
391
293
|
service_key: Optional[Key] = None,
|
392
|
-
|
393
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
394
|
-
labels: OptionalStringToStringDict = None,
|
395
|
-
aggregate_file_name: OptionalString = None,
|
396
|
-
inidividual_log: bool = True,
|
294
|
+
config: Config,
|
397
295
|
):
|
398
296
|
super().__init__(
|
399
|
-
|
400
|
-
type=LoggerType.SERVICE,
|
297
|
+
LoggerType.SERVICE,
|
401
298
|
environment=environment,
|
402
299
|
service_key=service_key,
|
403
300
|
client_key=None,
|
404
|
-
|
405
|
-
google_cloud_logging=google_cloud_logging,
|
406
|
-
labels=labels,
|
407
|
-
aggregate_file_name=aggregate_file_name,
|
408
|
-
inidividual_log=inidividual_log,
|
301
|
+
config=config,
|
409
302
|
)
|
410
303
|
|
411
304
|
|
412
305
|
@overload
|
413
306
|
def create(
|
414
|
-
dir: str,
|
415
307
|
type: Literal[LoggerType.APPLICATION],
|
416
308
|
*,
|
417
309
|
environment: Optional[Environment] = None,
|
418
310
|
service_key: Optional[Key] = None,
|
419
|
-
|
420
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
421
|
-
labels: OptionalStringToStringDict = None,
|
422
|
-
aggregate_file_name: OptionalString = None,
|
423
|
-
inidividual_log: bool = True,
|
311
|
+
config: Config,
|
424
312
|
) -> Application: ...
|
425
313
|
@overload
|
426
314
|
def create(
|
427
|
-
dir: str,
|
428
315
|
type: Literal[LoggerType.CACHE],
|
429
316
|
*,
|
430
317
|
environment: Optional[Environment] = None,
|
431
318
|
service_key: Optional[Key] = None,
|
432
|
-
|
433
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
434
|
-
labels: OptionalStringToStringDict = None,
|
435
|
-
aggregate_file_name: OptionalString = None,
|
436
|
-
inidividual_log: bool = True,
|
319
|
+
config: Config,
|
437
320
|
) -> Cache: ...
|
438
321
|
@overload
|
439
322
|
def create(
|
440
|
-
dir: str,
|
441
323
|
type: Literal[LoggerType.CLIENT],
|
442
324
|
*,
|
443
325
|
environment: Optional[Environment] = None,
|
444
326
|
service_key: Optional[Key] = None,
|
445
327
|
client_key: str,
|
446
|
-
|
447
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
448
|
-
labels: OptionalStringToStringDict = None,
|
449
|
-
aggregate_file_name: OptionalString = None,
|
450
|
-
inidividual_log: bool = True,
|
328
|
+
config: Config,
|
451
329
|
) -> Client: ...
|
452
330
|
@overload
|
453
331
|
def create(
|
454
|
-
dir: str,
|
455
332
|
type: Literal[LoggerType.CONTROLLER],
|
456
333
|
*,
|
457
334
|
environment: Optional[Environment] = None,
|
458
335
|
service_key: Optional[Key] = None,
|
459
|
-
|
460
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
461
|
-
labels: OptionalStringToStringDict = None,
|
462
|
-
aggregate_file_name: OptionalString = None,
|
463
|
-
inidividual_log: bool = True,
|
336
|
+
config: Config,
|
464
337
|
) -> Controller: ...
|
465
338
|
@overload
|
466
339
|
def create(
|
467
|
-
dir: str,
|
468
340
|
type: Literal[LoggerType.DATABASE],
|
469
341
|
*,
|
470
342
|
environment: Optional[Environment] = None,
|
471
343
|
service_key: Optional[Key] = None,
|
472
|
-
|
473
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
474
|
-
labels: OptionalStringToStringDict = None,
|
475
|
-
aggregate_file_name: OptionalString = None,
|
476
|
-
inidividual_log: bool = True,
|
344
|
+
config: Config,
|
477
345
|
) -> Database: ...
|
478
346
|
@overload
|
479
347
|
def create(
|
480
|
-
|
348
|
+
type: Literal[LoggerType.EXCEPTION],
|
349
|
+
*,
|
350
|
+
environment: Optional[Environment] = None,
|
351
|
+
service_key: Optional[Key] = None,
|
352
|
+
config: Config,
|
353
|
+
) -> Exception: ...
|
354
|
+
@overload
|
355
|
+
def create(
|
481
356
|
type: Literal[LoggerType.MIDDLEWARE],
|
482
357
|
*,
|
483
358
|
environment: Optional[Environment] = None,
|
484
359
|
service_key: Optional[Key] = None,
|
485
|
-
|
486
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
487
|
-
labels: OptionalStringToStringDict = None,
|
488
|
-
aggregate_file_name: OptionalString = None,
|
489
|
-
inidividual_log: bool = True,
|
360
|
+
config: Config,
|
490
361
|
) -> Middleware: ...
|
491
362
|
@overload
|
492
363
|
def create(
|
493
|
-
dir: str,
|
494
364
|
type: Literal[LoggerType.REPOSITORY],
|
495
365
|
*,
|
496
366
|
environment: Optional[Environment] = None,
|
497
367
|
service_key: Optional[Key] = None,
|
498
|
-
|
499
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
500
|
-
labels: OptionalStringToStringDict = None,
|
501
|
-
aggregate_file_name: OptionalString = None,
|
502
|
-
inidividual_log: bool = True,
|
368
|
+
config: Config,
|
503
369
|
) -> Repository: ...
|
504
370
|
@overload
|
505
371
|
def create(
|
506
|
-
dir: str,
|
507
372
|
type: Literal[LoggerType.SERVICE],
|
508
373
|
*,
|
509
374
|
environment: Optional[Environment] = None,
|
510
375
|
service_key: Optional[Key] = None,
|
511
|
-
|
512
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
513
|
-
labels: OptionalStringToStringDict = None,
|
514
|
-
aggregate_file_name: OptionalString = None,
|
515
|
-
inidividual_log: bool = True,
|
376
|
+
config: Config,
|
516
377
|
) -> Service: ...
|
517
378
|
def create(
|
518
|
-
dir: str,
|
519
379
|
type: LoggerType = LoggerType.BASE,
|
520
380
|
*,
|
521
381
|
environment: Optional[Environment] = None,
|
522
382
|
service_key: Optional[Key] = None,
|
523
383
|
client_key: OptionalString = None,
|
524
|
-
|
525
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = None,
|
526
|
-
labels: OptionalStringToStringDict = None,
|
527
|
-
aggregate_file_name: OptionalString = None,
|
528
|
-
inidividual_log: bool = True,
|
384
|
+
config: Config,
|
529
385
|
) -> Union[
|
530
386
|
Base,
|
531
387
|
Application,
|
@@ -538,43 +394,24 @@ def create(
|
|
538
394
|
Repository,
|
539
395
|
Service,
|
540
396
|
]:
|
541
|
-
if type not in LoggerType:
|
542
|
-
raise ValueError(f"Invalid logger type of '{type}'")
|
543
|
-
|
544
397
|
if type is LoggerType.BASE:
|
545
398
|
return Base(
|
546
|
-
type=type,
|
547
|
-
dir=dir,
|
548
399
|
environment=environment,
|
549
400
|
service_key=service_key,
|
550
401
|
client_key=client_key,
|
551
|
-
|
552
|
-
google_cloud_logging=google_cloud_logging,
|
553
|
-
labels=labels,
|
554
|
-
aggregate_file_name=aggregate_file_name,
|
555
|
-
inidividual_log=inidividual_log,
|
402
|
+
config=config,
|
556
403
|
)
|
557
404
|
elif type is LoggerType.APPLICATION:
|
558
405
|
return Application(
|
559
|
-
dir=dir,
|
560
406
|
environment=environment,
|
561
407
|
service_key=service_key,
|
562
|
-
|
563
|
-
google_cloud_logging=google_cloud_logging,
|
564
|
-
labels=labels,
|
565
|
-
aggregate_file_name=aggregate_file_name,
|
566
|
-
inidividual_log=inidividual_log,
|
408
|
+
config=config,
|
567
409
|
)
|
568
410
|
elif type is LoggerType.CACHE:
|
569
411
|
return Cache(
|
570
|
-
dir=dir,
|
571
412
|
environment=environment,
|
572
413
|
service_key=service_key,
|
573
|
-
|
574
|
-
google_cloud_logging=google_cloud_logging,
|
575
|
-
labels=labels,
|
576
|
-
aggregate_file_name=aggregate_file_name,
|
577
|
-
inidividual_log=inidividual_log,
|
414
|
+
config=config,
|
578
415
|
)
|
579
416
|
elif type is LoggerType.CLIENT:
|
580
417
|
if client_key is None:
|
@@ -582,79 +419,116 @@ def create(
|
|
582
419
|
"Argument 'client_key' can not be None if 'logger_type' is 'client'"
|
583
420
|
)
|
584
421
|
return Client(
|
585
|
-
dir=dir,
|
586
|
-
client_key=client_key,
|
587
422
|
environment=environment,
|
588
423
|
service_key=service_key,
|
589
|
-
|
590
|
-
|
591
|
-
labels=labels,
|
592
|
-
aggregate_file_name=aggregate_file_name,
|
593
|
-
inidividual_log=inidividual_log,
|
424
|
+
client_key=client_key,
|
425
|
+
config=config,
|
594
426
|
)
|
595
427
|
elif type is LoggerType.CONTROLLER:
|
596
428
|
return Controller(
|
597
|
-
dir=dir,
|
598
429
|
environment=environment,
|
599
430
|
service_key=service_key,
|
600
|
-
|
601
|
-
google_cloud_logging=google_cloud_logging,
|
602
|
-
labels=labels,
|
603
|
-
aggregate_file_name=aggregate_file_name,
|
604
|
-
inidividual_log=inidividual_log,
|
431
|
+
config=config,
|
605
432
|
)
|
606
433
|
elif type is LoggerType.DATABASE:
|
607
434
|
return Database(
|
608
|
-
dir=dir,
|
609
435
|
environment=environment,
|
610
436
|
service_key=service_key,
|
611
|
-
|
612
|
-
google_cloud_logging=google_cloud_logging,
|
613
|
-
labels=labels,
|
614
|
-
aggregate_file_name=aggregate_file_name,
|
615
|
-
inidividual_log=inidividual_log,
|
437
|
+
config=config,
|
616
438
|
)
|
617
439
|
elif type is LoggerType.EXCEPTION:
|
618
440
|
return Exception(
|
619
|
-
dir=dir,
|
620
441
|
environment=environment,
|
621
442
|
service_key=service_key,
|
622
|
-
|
623
|
-
google_cloud_logging=google_cloud_logging,
|
624
|
-
labels=labels,
|
625
|
-
aggregate_file_name=aggregate_file_name,
|
626
|
-
inidividual_log=inidividual_log,
|
443
|
+
config=config,
|
627
444
|
)
|
628
445
|
elif type is LoggerType.MIDDLEWARE:
|
629
446
|
return Middleware(
|
630
|
-
dir=dir,
|
631
447
|
environment=environment,
|
632
448
|
service_key=service_key,
|
633
|
-
|
634
|
-
google_cloud_logging=google_cloud_logging,
|
635
|
-
labels=labels,
|
636
|
-
aggregate_file_name=aggregate_file_name,
|
637
|
-
inidividual_log=inidividual_log,
|
449
|
+
config=config,
|
638
450
|
)
|
639
451
|
elif type is LoggerType.REPOSITORY:
|
640
452
|
return Repository(
|
641
|
-
dir=dir,
|
642
453
|
environment=environment,
|
643
454
|
service_key=service_key,
|
644
|
-
|
645
|
-
google_cloud_logging=google_cloud_logging,
|
646
|
-
labels=labels,
|
647
|
-
aggregate_file_name=aggregate_file_name,
|
648
|
-
inidividual_log=inidividual_log,
|
455
|
+
config=config,
|
649
456
|
)
|
650
457
|
elif type is LoggerType.SERVICE:
|
651
458
|
return Service(
|
652
|
-
dir=dir,
|
653
459
|
environment=environment,
|
654
460
|
service_key=service_key,
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
461
|
+
config=config,
|
462
|
+
)
|
463
|
+
|
464
|
+
|
465
|
+
class Loggers(BaseModel):
|
466
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
467
|
+
|
468
|
+
application: Application = Field(..., description="Application logger")
|
469
|
+
cache: Cache = Field(..., description="Cache logger")
|
470
|
+
controller: Controller = Field(..., description="Controller logger")
|
471
|
+
database: Database = Field(..., description="Database logger")
|
472
|
+
exception: Exception = Field(..., description="Exception logger")
|
473
|
+
middleware: Middleware = Field(..., description="Middleware logger")
|
474
|
+
repository: Repository = Field(..., description="Repository logger")
|
475
|
+
service: Service = Field(..., description="Service logger")
|
476
|
+
|
477
|
+
@classmethod
|
478
|
+
def create(
|
479
|
+
cls,
|
480
|
+
*,
|
481
|
+
environment: Optional[Environment] = None,
|
482
|
+
service_key: Optional[Key] = None,
|
483
|
+
config: Config,
|
484
|
+
) -> "Loggers":
|
485
|
+
return cls(
|
486
|
+
application=create(
|
487
|
+
LoggerType.APPLICATION,
|
488
|
+
environment=environment,
|
489
|
+
service_key=service_key,
|
490
|
+
config=config,
|
491
|
+
),
|
492
|
+
cache=create(
|
493
|
+
LoggerType.CACHE,
|
494
|
+
environment=environment,
|
495
|
+
service_key=service_key,
|
496
|
+
config=config,
|
497
|
+
),
|
498
|
+
controller=create(
|
499
|
+
LoggerType.CONTROLLER,
|
500
|
+
environment=environment,
|
501
|
+
service_key=service_key,
|
502
|
+
config=config,
|
503
|
+
),
|
504
|
+
database=create(
|
505
|
+
LoggerType.DATABASE,
|
506
|
+
environment=environment,
|
507
|
+
service_key=service_key,
|
508
|
+
config=config,
|
509
|
+
),
|
510
|
+
exception=create(
|
511
|
+
LoggerType.EXCEPTION,
|
512
|
+
environment=environment,
|
513
|
+
service_key=service_key,
|
514
|
+
config=config,
|
515
|
+
),
|
516
|
+
middleware=create(
|
517
|
+
LoggerType.MIDDLEWARE,
|
518
|
+
environment=environment,
|
519
|
+
service_key=service_key,
|
520
|
+
config=config,
|
521
|
+
),
|
522
|
+
repository=create(
|
523
|
+
LoggerType.REPOSITORY,
|
524
|
+
environment=environment,
|
525
|
+
service_key=service_key,
|
526
|
+
config=config,
|
527
|
+
),
|
528
|
+
service=create(
|
529
|
+
LoggerType.SERVICE,
|
530
|
+
environment=environment,
|
531
|
+
service_key=service_key,
|
532
|
+
config=config,
|
533
|
+
),
|
660
534
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: maleo-logging
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.7
|
4
4
|
Summary: Logging package for MaleoSuite
|
5
5
|
Author-email: Agra Bima Yuda <agra@nexmedis.com>
|
6
6
|
License: Proprietary
|
@@ -35,7 +35,7 @@ Requires-Dist: idna>=3.10
|
|
35
35
|
Requires-Dist: importlib_metadata>=8.7.0
|
36
36
|
Requires-Dist: maleo-enums>=0.0.6
|
37
37
|
Requires-Dist: maleo-types-base>=0.0.2
|
38
|
-
Requires-Dist: maleo-utils>=0.0.
|
38
|
+
Requires-Dist: maleo-utils>=0.0.5
|
39
39
|
Requires-Dist: mypy_extensions>=1.1.0
|
40
40
|
Requires-Dist: nodeenv>=1.9.1
|
41
41
|
Requires-Dist: opentelemetry-api>=1.36.0
|
@@ -0,0 +1,10 @@
|
|
1
|
+
maleo/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
maleo/logging/config.py,sha256=eOeMJqDCoH2i_Sqmr1FzuSMklmT61XrB1pCqXU8YZ5s,1208
|
3
|
+
maleo/logging/enums.py,sha256=GrM5rC5k8ErR3fcq9W1VrKkTe1B-u5z61lGzqTVukpY,578
|
4
|
+
maleo/logging/google.py,sha256=h4ZiPbCCOdSOGdSXOzEFlJyCzNBcsoAzb5w_YtV9ipc,1443
|
5
|
+
maleo/logging/logger.py,sha256=TSRvSNliu2G5HVzKQOL7kr9draiVoVm7D8onPAHwAo8,15616
|
6
|
+
maleo_logging-0.0.7.dist-info/licenses/LICENSE,sha256=aftGsecnk7TWVX-7KW94FqK4Syy6YSZ8PZEF7EcIp3M,2621
|
7
|
+
maleo_logging-0.0.7.dist-info/METADATA,sha256=z1JbfP-R7kN_bf4J6_4n-dweY8WeVRAelOucBTz_jO4,2709
|
8
|
+
maleo_logging-0.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
+
maleo_logging-0.0.7.dist-info/top_level.txt,sha256=3Tpd1siVsfYoeI9FEOJNYnffx_shzZ3wsPpTvz5bljc,6
|
10
|
+
maleo_logging-0.0.7.dist-info/RECORD,,
|
maleo/logging/dtos.py
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
from pydantic import BaseModel, Field, ConfigDict
|
2
|
-
from typing import Optional
|
3
|
-
from maleo.enums.environment import Environment
|
4
|
-
from maleo.enums.service import Key
|
5
|
-
from maleo.types.base.string import OptionalString
|
6
|
-
from .enums import Level, LoggerType
|
7
|
-
from .google import GoogleCloudLogging
|
8
|
-
|
9
|
-
|
10
|
-
class Labels(BaseModel):
|
11
|
-
logger_type: LoggerType = Field(..., description="Logger's type")
|
12
|
-
service_environment: Environment = Field(..., description="Service's environment")
|
13
|
-
service_key: Key = Field(..., description="Service's key")
|
14
|
-
client_key: OptionalString = Field(None, description="Client's key (Optional)")
|
15
|
-
|
16
|
-
|
17
|
-
class SimpleConfig(BaseModel):
|
18
|
-
model_config = ConfigDict(arbitrary_types_allowed=True)
|
19
|
-
|
20
|
-
dir: str = Field(..., description="Log's directory")
|
21
|
-
level: Level = Field(Level.INFO, description="Log's level")
|
22
|
-
google_cloud_logging: Optional[GoogleCloudLogging] = Field(
|
23
|
-
default_factory=GoogleCloudLogging, description="Google cloud logging"
|
24
|
-
)
|
@@ -1,10 +0,0 @@
|
|
1
|
-
maleo/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
maleo/logging/dtos.py,sha256=CqRERlS8TVzj7v7JaDwqNbjfgzFB6BDHBepvjvn-D5Y,984
|
3
|
-
maleo/logging/enums.py,sha256=GrM5rC5k8ErR3fcq9W1VrKkTe1B-u5z61lGzqTVukpY,578
|
4
|
-
maleo/logging/google.py,sha256=h4ZiPbCCOdSOGdSXOzEFlJyCzNBcsoAzb5w_YtV9ipc,1443
|
5
|
-
maleo/logging/logger.py,sha256=9e-P8LZIPF7TV3LLmJyaX8mUUbJ_N27tTxyClncydrc,21227
|
6
|
-
maleo_logging-0.0.5.dist-info/licenses/LICENSE,sha256=aftGsecnk7TWVX-7KW94FqK4Syy6YSZ8PZEF7EcIp3M,2621
|
7
|
-
maleo_logging-0.0.5.dist-info/METADATA,sha256=qE3E-xVNtVqfJANlHhW1NAOD37ApNEXGSmrHnpBwwgE,2709
|
8
|
-
maleo_logging-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
-
maleo_logging-0.0.5.dist-info/top_level.txt,sha256=3Tpd1siVsfYoeI9FEOJNYnffx_shzZ3wsPpTvz5bljc,6
|
10
|
-
maleo_logging-0.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|