Created
October 25, 2023 13:50
-
-
Save AliRn76/3185cb9341d07d439db1d7da8109c41e to your computer and use it in GitHub Desktop.
Customer Handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
class CustomHandler: | |
""" | |
Handler that controls the writing of the newline character | |
""" | |
special_code = "[!n]" | |
def emit(self, record) -> None: | |
if self.special_code in record.msg: | |
record.msg = record.msg.replace(self.special_code, "") | |
self.terminator = "" | |
else: | |
self.terminator = "\n" | |
return super().emit(record) | |
class CustomFileHandler(CustomHandler, logging.FileHandler): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment