Skip to content

Commit 0b604c6

Browse files
committed
🎯 feat: move logging trace data to the base object.
1 parent cb6b027 commit 0b604c6

5 files changed

Lines changed: 149 additions & 97 deletions

File tree

src/ddeutil/workflow/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,13 @@ def is_ignore(
327327
*,
328328
ignore_filename: Optional[str] = None,
329329
) -> bool:
330-
"""Check this file was ignored.
330+
"""Check this file was ignored from the `.confignore` format.
331331
332332
:param file: (Path) A file path that want to check.
333333
:param path: (Path) A config path that want to read the config
334334
ignore file.
335335
:param ignore_filename: (str) An ignore filename. Default is
336-
`.confignore` filename.
336+
``.confignore`` filename.
337337
338338
:rtype: bool
339339
"""

src/ddeutil/workflow/errors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ def to_dict(exception: Exception, **kwargs) -> ErrorData: # pragma: no cov
3838

3939

4040
class BaseError(Exception):
41-
"""Base Workflow exception class will implement the `refs` argument for
41+
"""Base Workflow exception class will implement the ``refs`` argument for
4242
making an error context to the result context.
43+
44+
Attributes:
45+
refs: (:obj:str, optional)
46+
context: (:obj:DictData)
47+
params: (:obj:DictData)
48+
4349
"""
4450

4551
def __init__(

src/ddeutil/workflow/reusables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
T = TypeVar("T")
4545
P = ParamSpec("P")
4646

47-
# NOTE: Adjust logging level of the `asyncio` to INFO level.
47+
# NOTE: Adjust logging level of the ``asyncio`` to INFO level.
4848
logging.getLogger("asyncio").setLevel(logging.INFO)
4949

5050

src/ddeutil/workflow/traces.py

Lines changed: 120 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,124 @@ def make_message(self, message: str) -> str:
333333
"Adjust make message method for this trace object before using."
334334
)
335335

336+
@abstractmethod
337+
def _logging(
338+
self,
339+
message: str,
340+
mode: str,
341+
*,
342+
is_err: bool = False,
343+
):
344+
"""Write trace log with append mode and logging this message with any
345+
logging level.
346+
347+
:param message: (str) A message that want to log.
348+
:param mode: (str)
349+
:param is_err: (bool)
350+
"""
351+
raise NotImplementedError(
352+
"Logging action should be implement for making trace log."
353+
)
354+
355+
def debug(self, message: str):
356+
"""Write trace log with append mode and logging this message with the
357+
DEBUG level.
358+
359+
:param message: (str) A message that want to log.
360+
"""
361+
self._logging(message, mode="debug")
362+
363+
def info(self, message: str) -> None:
364+
"""Write trace log with append mode and logging this message with the
365+
INFO level.
366+
367+
:param message: (str) A message that want to log.
368+
"""
369+
self._logging(message, mode="info")
370+
371+
def warning(self, message: str) -> None:
372+
"""Write trace log with append mode and logging this message with the
373+
WARNING level.
374+
375+
:param message: (str) A message that want to log.
376+
"""
377+
self._logging(message, mode="warning")
378+
379+
def error(self, message: str) -> None:
380+
"""Write trace log with append mode and logging this message with the
381+
ERROR level.
382+
383+
:param message: (str) A message that want to log.
384+
"""
385+
self._logging(message, mode="error", is_err=True)
386+
387+
def exception(self, message: str) -> None:
388+
"""Write trace log with append mode and logging this message with the
389+
EXCEPTION level.
390+
391+
:param message: (str) A message that want to log.
392+
"""
393+
self._logging(message, mode="exception", is_err=True)
394+
395+
@abstractmethod
396+
async def _alogging(
397+
self,
398+
message: str,
399+
mode: str,
400+
*,
401+
is_err: bool = False,
402+
) -> None:
403+
"""Async write trace log with append mode and logging this message with
404+
any logging level.
405+
406+
:param message: (str) A message that want to log.
407+
:param mode: (str)
408+
:param is_err: (bool)
409+
"""
410+
raise NotImplementedError(
411+
"Async Logging action should be implement for making trace log."
412+
)
413+
414+
async def adebug(self, message: str) -> None: # pragma: no cov
415+
"""Async write trace log with append mode and logging this message with
416+
the DEBUG level.
417+
418+
:param message: (str) A message that want to log.
419+
"""
420+
await self._alogging(message, mode="debug")
421+
422+
async def ainfo(self, message: str) -> None: # pragma: no cov
423+
"""Async write trace log with append mode and logging this message with
424+
the INFO level.
425+
426+
:param message: (str) A message that want to log.
427+
"""
428+
await self._alogging(message, mode="info")
429+
430+
async def awarning(self, message: str) -> None: # pragma: no cov
431+
"""Async write trace log with append mode and logging this message with
432+
the WARNING level.
433+
434+
:param message: (str) A message that want to log.
435+
"""
436+
await self._alogging(message, mode="warning")
437+
438+
async def aerror(self, message: str) -> None: # pragma: no cov
439+
"""Async write trace log with append mode and logging this message with
440+
the ERROR level.
441+
442+
:param message: (str) A message that want to log.
443+
"""
444+
await self._alogging(message, mode="error", is_err=True)
445+
446+
async def aexception(self, message: str) -> None: # pragma: no cov
447+
"""Async write trace log with append mode and logging this message with
448+
the EXCEPTION level.
449+
450+
:param message: (str) A message that want to log.
451+
"""
452+
await self._alogging(message, mode="exception", is_err=True)
453+
336454

337455
class ConsoleTrace(BaseTrace): # pragma: no cov
338456
"""Console Trace log model."""
@@ -416,7 +534,7 @@ def make_message(self, message: str) -> str:
416534
f"{PrefixMsg.from_str(message).prepare(self.extras)}"
417535
)
418536

419-
def __logging(
537+
def _logging(
420538
self, message: str, mode: str, *, is_err: bool = False
421539
) -> None:
422540
"""Write trace log with append mode and logging this message with any
@@ -433,47 +551,7 @@ def __logging(
433551

434552
getattr(logger, mode)(msg, stacklevel=3, extra={"cut_id": self.cut_id})
435553

436-
def debug(self, message: str):
437-
"""Write trace log with append mode and logging this message with the
438-
DEBUG level.
439-
440-
:param message: (str) A message that want to log.
441-
"""
442-
self.__logging(message, mode="debug")
443-
444-
def info(self, message: str) -> None:
445-
"""Write trace log with append mode and logging this message with the
446-
INFO level.
447-
448-
:param message: (str) A message that want to log.
449-
"""
450-
self.__logging(message, mode="info")
451-
452-
def warning(self, message: str) -> None:
453-
"""Write trace log with append mode and logging this message with the
454-
WARNING level.
455-
456-
:param message: (str) A message that want to log.
457-
"""
458-
self.__logging(message, mode="warning")
459-
460-
def error(self, message: str) -> None:
461-
"""Write trace log with append mode and logging this message with the
462-
ERROR level.
463-
464-
:param message: (str) A message that want to log.
465-
"""
466-
self.__logging(message, mode="error", is_err=True)
467-
468-
def exception(self, message: str) -> None:
469-
"""Write trace log with append mode and logging this message with the
470-
EXCEPTION level.
471-
472-
:param message: (str) A message that want to log.
473-
"""
474-
self.__logging(message, mode="exception", is_err=True)
475-
476-
async def __alogging(
554+
async def _alogging(
477555
self, message: str, mode: str, *, is_err: bool = False
478556
) -> None:
479557
"""Write trace log with append mode and logging this message with any
@@ -490,46 +568,6 @@ async def __alogging(
490568

491569
getattr(logger, mode)(msg, stacklevel=3, extra={"cut_id": self.cut_id})
492570

493-
async def adebug(self, message: str) -> None: # pragma: no cov
494-
"""Async write trace log with append mode and logging this message with
495-
the DEBUG level.
496-
497-
:param message: (str) A message that want to log.
498-
"""
499-
await self.__alogging(message, mode="debug")
500-
501-
async def ainfo(self, message: str) -> None: # pragma: no cov
502-
"""Async write trace log with append mode and logging this message with
503-
the INFO level.
504-
505-
:param message: (str) A message that want to log.
506-
"""
507-
await self.__alogging(message, mode="info")
508-
509-
async def awarning(self, message: str) -> None: # pragma: no cov
510-
"""Async write trace log with append mode and logging this message with
511-
the WARNING level.
512-
513-
:param message: (str) A message that want to log.
514-
"""
515-
await self.__alogging(message, mode="warning")
516-
517-
async def aerror(self, message: str) -> None: # pragma: no cov
518-
"""Async write trace log with append mode and logging this message with
519-
the ERROR level.
520-
521-
:param message: (str) A message that want to log.
522-
"""
523-
await self.__alogging(message, mode="error", is_err=True)
524-
525-
async def aexception(self, message: str) -> None: # pragma: no cov
526-
"""Async write trace log with append mode and logging this message with
527-
the EXCEPTION level.
528-
529-
:param message: (str) A message that want to log.
530-
"""
531-
await self.__alogging(message, mode="exception", is_err=True)
532-
533571

534572
class FileTrace(ConsoleTrace): # pragma: no cov
535573
"""File Trace dataclass that write file to the local storage."""

src/ddeutil/workflow/utils.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,23 @@ def gen_id(
163163
extras: DictData | None = None,
164164
) -> str:
165165
"""Generate running ID for able to tracking. This generates process use
166-
`md5` algorithm function if `WORKFLOW_CORE_WORKFLOW_ID_SIMPLE_MODE` set
166+
``md5`` algorithm function if ``WORKFLOW_CORE_WORKFLOW_ID_SIMPLE_MODE`` set
167167
to false. But it will cut this hashing value length to 10 it the setting
168168
value set to true.
169169
170170
Simple Mode:
171171
172-
... 0000 00 00 00 00 00 000000 T 0000000000
173-
... year month day hour minute second microsecond sep simple-id
172+
... 0000 00 00 00 00 00 000000 T 0000000000
173+
... year month day hour minute second microsecond sep simple-id
174174
175175
:param value: A value that want to add to prefix before hashing with md5.
176-
:param sensitive: A flag that convert the value to lower case before hashing
177-
:param unique: A flag that add timestamp at microsecond level to value
178-
before hashing.
179-
:param simple_mode: A flag for generate ID by simple mode.
180-
:param extras: An extra parameter that use for override config value.
176+
:param sensitive: (bool) A flag that enable to convert the value to lower
177+
case before hashing that value before generate ID.
178+
:param unique: (bool) A flag that add timestamp at microsecond level to
179+
value before hashing.
180+
:param simple_mode: (bool | None) A flag for generate ID by simple mode.
181+
:param extras: (DictData) An extra parameter that use for override config
182+
value.
181183
182184
:rtype: str
183185
"""
@@ -212,7 +214,8 @@ def default_gen_id() -> str:
212214
def make_exec(path: Union[Path, str]) -> None:
213215
"""Change mode of file to be executable file.
214216
215-
:param path: A file path that want to make executable permission.
217+
:param path: (Path | str) A file path that want to make executable
218+
permission.
216219
"""
217220
f: Path = Path(path) if isinstance(path, str) else path
218221
f.chmod(f.stat().st_mode | stat.S_IEXEC)
@@ -285,9 +288,14 @@ def dump_all(value: T, by_alias: bool = False) -> T: ... # pragma: no cov
285288

286289

287290
def dump_all(
288-
value: Union[T, BaseModel], by_alias: bool = False
291+
value: Union[T, BaseModel],
292+
by_alias: bool = False,
289293
) -> Union[T, DictData]:
290-
"""Dump all BaseModel object to dict."""
294+
"""Dump all nested BaseModel object to dict object.
295+
296+
:param value: (T | BaseModel)
297+
:param by_alias: (bool)
298+
"""
291299
if isinstance(value, dict):
292300
return {k: dump_all(value[k], by_alias=by_alias) for k in value}
293301
elif isinstance(value, (list, tuple, set)):

0 commit comments

Comments
 (0)