Skip to content

Commit

Permalink
customformatter to remove markup in logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
simonc56 committed May 14, 2023
1 parent a04e49c commit fdc108a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion plextraktsync/logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re

from .factory import factory

Expand All @@ -17,7 +18,7 @@ def initialize(config):
mode = "a" if config.log_append else "w"
file_handler = logging.FileHandler(config.log_file, mode, "utf-8")
file_handler.setFormatter(
logging.Formatter("%(asctime)-15s %(levelname)s[%(name)s]:%(message)s")
CustomFormatter("%(asctime)-15s %(levelname)s[%(name)s]:%(message)s")
)
file_handler.setLevel(logging.DEBUG)

Expand All @@ -34,3 +35,12 @@ def initialize(config):

logger.removeHandler(loghandler)
logger.setLevel(logging.DEBUG)

class CustomFormatter(logging.Formatter):
def format(self, record):
record.msg = self.remove_markup(record.msg)
return super().format(record)

def remove_markup(self, text):
pattern = r'\[link=[^\]]*\]|(\[green\])|(\[\/\])'
return re.sub(pattern, '', text)

0 comments on commit fdc108a

Please sign in to comment.