Coverage for C:\src\imod-python\imod\logging\ilogger.py: 59%
32 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-08 10:26 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-08 10:26 +0200
1from abc import abstractmethod
3from imod.logging.loglevel import LogLevel
6class ILogger:
7 """
8 Interface to be implemented by all logger wrappers.
9 """
11 @abstractmethod
12 def debug(self, message: str, additional_depth: int) -> None:
13 """
14 Log message with severity ':attr:`~imod.logging.loglevel.LogLevel.DEBUG`'.
16 Parameters
17 ----------
18 message : str
19 message to be logged
20 additional_depth: Optional[int]
21 additional depth level. Use this to correct the filename and line number
22 when you add logging to a decorator
23 """
24 raise NotImplementedError
26 @abstractmethod
27 def info(self, message: str, additional_depth: int) -> None:
28 """
29 Log message with severity ':attr:`~imod.logging.loglevel.LogLevel.INFO`'.
31 Parameters
32 ----------
33 message : str
34 message to be logged
35 additional_depth: Optional[int]
36 additional depth level. Use this to correct the filename and line number
37 when you add logging to a decorator
38 """
39 raise NotImplementedError
41 @abstractmethod
42 def warning(self, message: str, additional_depth: int) -> None:
43 """
44 Log message with severity ':attr:`~imod.logging.loglevel.LogLevel.WARNING`'.
46 Parameters
47 ----------
48 message : str
49 message to be logged
50 additional_depth: Optional[int]
51 additional depth level. Use this to correct the filename and line number
52 when you add logging to a decorator
53 """
54 raise NotImplementedError
56 @abstractmethod
57 def error(self, message: str, additional_depth: int) -> None:
58 """
59 Log message with severity ':attr:`~imod.logging.loglevel.LogLevel.ERROR`'.
61 Parameters
62 ----------
63 message : str
64 message to be logged
65 additional_depth: Optional[int]
66 additional depth level. Use this to correct the filename and line number
67 when you add logging to a decorator
68 """
69 raise NotImplementedError
71 @abstractmethod
72 def critical(self, message: str, additional_depth: int) -> None:
73 """
74 Log message with severity ':attr:`~imod.logging.loglevel.LogLevel.CRITICAL`'.
76 Parameters
77 ----------
78 message : str
79 message to be logged
80 additional_depth: Optional[int]
81 additional depth level. Use this to correct the filename and line number
82 when you add logging to a decorator
83 """
84 raise NotImplementedError
86 def log(self, loglevel: LogLevel, message: str, additional_depth: int) -> None:
87 """
88 logs a message with the specified urgency level.
89 """
90 match loglevel:
91 case LogLevel.DEBUG:
92 self.debug(message, additional_depth)
93 case LogLevel.INFO:
94 self.info(message, additional_depth)
95 case LogLevel.WARNING:
96 self.warning(message, additional_depth)
97 case LogLevel.ERROR:
98 self.error(message, additional_depth)
99 case LogLevel.CRITICAL:
100 self.critical(message, additional_depth)
101 case _:
102 raise ValueError(f"Unknown logging urgency at level {loglevel}")