Skip to content

Instantly share code, notes, and snippets.

@AliRn76
Created October 25, 2023 13:50
Show Gist options
  • Save AliRn76/3185cb9341d07d439db1d7da8109c41e to your computer and use it in GitHub Desktop.
Save AliRn76/3185cb9341d07d439db1d7da8109c41e to your computer and use it in GitHub Desktop.
Customer Handler
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