Skip to content
Snippets Groups Projects
Commit 144aeb39 authored by DEBREUVE Eric's avatar DEBREUVE Eric
Browse files

added exit_on_critical

parent 709083ac
No related branches found
No related tags found
No related merge requests found
......@@ -40,9 +40,10 @@ from logger_36.type.issue import NewIssue, issue_t
@d.dataclass(slots=True, repr=False, eq=False)
class logger_t(lggg.Logger):
name_: d.InitVar[str] = LOGGER_NAME
level: d.InitVar[int] = lggg.NOTSET
level_: d.InitVar[int] = lggg.NOTSET
activate_wrn_interceptions: d.InitVar[bool] = True
exit_on_error: bool = False
exit_on_error: bool = False # Implies exit_on_critical.
exit_on_critical: bool = False
# Must not be False until at least one handler has been added.
should_hold_messages: bool = True
......@@ -58,15 +59,17 @@ class logger_t(lggg.Logger):
)
def __post_init__(
self, name_: str, level: int, activate_wrn_interceptions: bool
self, name_: str, level_: int, activate_wrn_interceptions: bool
) -> None:
""""""
lggg.Logger.__init__(self, name_)
self.setLevel(level)
self.propagate = False
self.setLevel(level_)
self.propagate = False # Part of lggg.Logger.
if activate_wrn_interceptions:
self._ActivateWarningInterceptions()
if self.exit_on_error:
self.exit_on_critical = True
def _ActivateWarningInterceptions(self) -> None:
"""
......@@ -211,7 +214,10 @@ class logger_t(lggg.Logger):
else:
lggg.Logger.handle(self, record)
if self.exit_on_error and (record.levelno in (lggg.ERROR, lggg.CRITICAL)):
if (self.exit_on_critical and (record.levelno is lggg.CRITICAL)) or (
self.exit_on_error and (record.levelno is lggg.ERROR)):
# Also works if self.exit_on_error and record.levelno is lggg.CRITICAL since
# __post_init__ set self.exit_on_critical if self.exit_on_error.
sstm.exit(1)
def AddContextLevel(self, new_level: str, /) -> None:
......
......@@ -4,7 +4,7 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
SEE COPYRIGHT NOTICE BELOW
"""
__version__ = "2024.18"
__version__ = "2024.19"
"""
COPYRIGHT NOTICE
......
......@@ -122,6 +122,8 @@ sstm.stdout.writelines(
)
)
print("\n--- DONE")
"""
COPYRIGHT NOTICE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment