Content deleted Content added
→Python Example: MOS:HEAD |
→Python example: type hint |
||
Line 374:
class Logger(object):
"""Abstract handler in chain of responsibility pattern."""
__metaclass__ = ABCMeta
Line 399:
return self.next
def message(self, msg: str, severity: LogLevel) -> None:
"""Message writer handler.
msg (str): Message string. severity (LogLevel): Severity of message as log level enum.
"""
Line 412 ⟶ 413:
@abstractmethod
def write_message(self, msg: str) -> None:
"""Abstract method to write a message.
Abstract method to write a message.▼
msg (str): Message string. Raises: NotImplementedError
"""
Line 422 ⟶ 424:
class ConsoleLogger(Logger):
def write_message(self, msg: str) -> None:
"""Overrides parent's abstract method to write to console.▼
▲ Overrides parent's abstract method to write to console.
msg (str): Message string. """
print("Writing to console:", msg)
Line 431 ⟶ 434:
class EmailLogger(Logger):
"""Overrides parent's abstract method to send an email.▼
Arguments:
"""
def write_message(self, msg: str) -> None:▼
▲ Overrides parent's abstract method to send an email.
▲ Args: msg (str): Message string.
▲ def write_message(self, msg):
▲ print("Sending via email:", msg)
class FileLogger(Logger):
Arguments:
"""
def write_message(self, msg: str) -> None:▼
▲ Args: msg (str): Message string.
▲ def write_message(self, msg):
▲ print("Writing to log file:", msg)
def main():
"""Building the chain of responsibility."""▼
▲ Building the chain of responsibility.
logger = ConsoleLogger([LogLevel.ALL])
email_logger = logger.set_next(
|