mirror of
https://github.com/craigerl/aprsd.git
synced 2025-08-03 14:02:26 -04:00
Fix logging issue with log messages
This patch changes the base Message class to ensure that all printing of the message class only outputs the message in the truncated and bad word filtering enabled in the log.
This commit is contained in:
parent
03a20ebb5c
commit
e739441268
@ -184,6 +184,7 @@ class Message(metaclass=abc.ABCMeta):
|
|||||||
last_send_attempt = 0
|
last_send_attempt = 0
|
||||||
|
|
||||||
transport = None
|
transport = None
|
||||||
|
_raw_message = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -208,6 +209,23 @@ class Message(metaclass=abc.ABCMeta):
|
|||||||
def send(self):
|
def send(self):
|
||||||
"""Child class must declare."""
|
"""Child class must declare."""
|
||||||
|
|
||||||
|
def _filter_for_send(self):
|
||||||
|
"""Filter and format message string for FCC."""
|
||||||
|
# max? ftm400 displays 64, raw msg shows 74
|
||||||
|
# and ftm400-send is max 64. setting this to
|
||||||
|
# 67 displays 64 on the ftm400. (+3 {01 suffix)
|
||||||
|
# feature req: break long ones into two msgs
|
||||||
|
message = self._raw_message[:67]
|
||||||
|
# We all miss George Carlin
|
||||||
|
return re.sub("fuck|shit|cunt|piss|cock|bitch", "****", message)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def message(self):
|
||||||
|
return self._filter_for_send().rstrip("\n")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.message
|
||||||
|
|
||||||
|
|
||||||
class RawMessage(Message):
|
class RawMessage(Message):
|
||||||
"""Send a raw message.
|
"""Send a raw message.
|
||||||
@ -217,11 +235,11 @@ class RawMessage(Message):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
message = None
|
last_send_age = last_send_time = None
|
||||||
|
|
||||||
def __init__(self, message, allow_delay=True):
|
def __init__(self, message, allow_delay=True):
|
||||||
super().__init__(fromcall=None, tocall=None, msg_id=None, allow_delay=allow_delay)
|
super().__init__(fromcall=None, tocall=None, msg_id=None, allow_delay=allow_delay)
|
||||||
self.message = message
|
self._raw_message = message
|
||||||
|
|
||||||
def dict(self):
|
def dict(self):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
@ -230,17 +248,14 @@ class RawMessage(Message):
|
|||||||
last_send_age = str(now - self.last_send_time)
|
last_send_age = str(now - self.last_send_time)
|
||||||
return {
|
return {
|
||||||
"type": "raw",
|
"type": "raw",
|
||||||
"message": self.message.rstrip("\n"),
|
"message": self.message,
|
||||||
"raw": self.message.rstrip("\n"),
|
"raw": str(self),
|
||||||
"retry_count": self.retry_count,
|
"retry_count": self.retry_count,
|
||||||
"last_send_attempt": self.last_send_attempt,
|
"last_send_attempt": self.last_send_attempt,
|
||||||
"last_send_time": str(self.last_send_time),
|
"last_send_time": str(self.last_send_time),
|
||||||
"last_send_age": last_send_age,
|
"last_send_age": last_send_age,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.message
|
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
tracker = MsgTrack()
|
tracker = MsgTrack()
|
||||||
tracker.add(self)
|
tracker.add(self)
|
||||||
@ -252,7 +267,7 @@ class RawMessage(Message):
|
|||||||
cl = client.factory.create().client
|
cl = client.factory.create().client
|
||||||
log_message(
|
log_message(
|
||||||
"Sending Message Direct",
|
"Sending Message Direct",
|
||||||
str(self).rstrip("\n"),
|
str(self),
|
||||||
self.message,
|
self.message,
|
||||||
tocall=self.tocall,
|
tocall=self.tocall,
|
||||||
fromcall=self.fromcall,
|
fromcall=self.fromcall,
|
||||||
@ -264,7 +279,7 @@ class RawMessage(Message):
|
|||||||
class TextMessage(Message):
|
class TextMessage(Message):
|
||||||
"""Send regular ARPS text/command messages/replies."""
|
"""Send regular ARPS text/command messages/replies."""
|
||||||
|
|
||||||
message = None
|
last_send_time = last_send_age = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -278,7 +293,7 @@ class TextMessage(Message):
|
|||||||
fromcall=fromcall, tocall=tocall,
|
fromcall=fromcall, tocall=tocall,
|
||||||
msg_id=msg_id, allow_delay=allow_delay,
|
msg_id=msg_id, allow_delay=allow_delay,
|
||||||
)
|
)
|
||||||
self.message = message
|
self._raw_message = message
|
||||||
|
|
||||||
def dict(self):
|
def dict(self):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
@ -292,8 +307,8 @@ class TextMessage(Message):
|
|||||||
"type": "text-message",
|
"type": "text-message",
|
||||||
"fromcall": self.fromcall,
|
"fromcall": self.fromcall,
|
||||||
"tocall": self.tocall,
|
"tocall": self.tocall,
|
||||||
"message": self.message.rstrip("\n"),
|
"message": self.message,
|
||||||
"raw": str(self).rstrip("\n"),
|
"raw": str(self),
|
||||||
"retry_count": self.retry_count,
|
"retry_count": self.retry_count,
|
||||||
"last_send_attempt": self.last_send_attempt,
|
"last_send_attempt": self.last_send_attempt,
|
||||||
"last_send_time": str(self.last_send_time),
|
"last_send_time": str(self.last_send_time),
|
||||||
@ -305,20 +320,10 @@ class TextMessage(Message):
|
|||||||
return "{}>APZ100::{}:{}{{{}\n".format(
|
return "{}>APZ100::{}:{}{{{}\n".format(
|
||||||
self.fromcall,
|
self.fromcall,
|
||||||
self.tocall.ljust(9),
|
self.tocall.ljust(9),
|
||||||
self._filter_for_send(),
|
self.message,
|
||||||
str(self.id),
|
str(self.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _filter_for_send(self):
|
|
||||||
"""Filter and format message string for FCC."""
|
|
||||||
# max? ftm400 displays 64, raw msg shows 74
|
|
||||||
# and ftm400-send is max 64. setting this to
|
|
||||||
# 67 displays 64 on the ftm400. (+3 {01 suffix)
|
|
||||||
# feature req: break long ones into two msgs
|
|
||||||
message = self.message[:67]
|
|
||||||
# We all miss George Carlin
|
|
||||||
return re.sub("fuck|shit|cunt|piss|cock|bitch", "****", message)
|
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
tracker = MsgTrack()
|
tracker = MsgTrack()
|
||||||
tracker.add(self)
|
tracker.add(self)
|
||||||
@ -334,7 +339,7 @@ class TextMessage(Message):
|
|||||||
cl = client.factory.create().client
|
cl = client.factory.create().client
|
||||||
log_message(
|
log_message(
|
||||||
"Sending Message Direct",
|
"Sending Message Direct",
|
||||||
str(self).rstrip("\n"),
|
str(self),
|
||||||
self.message,
|
self.message,
|
||||||
tocall=self.tocall,
|
tocall=self.tocall,
|
||||||
fromcall=self.fromcall,
|
fromcall=self.fromcall,
|
||||||
@ -347,8 +352,8 @@ class TextMessage(Message):
|
|||||||
class SendMessageThread(threads.APRSDThread):
|
class SendMessageThread(threads.APRSDThread):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
self.msg = message
|
self.msg = message
|
||||||
name = self.msg.message[:5]
|
name = self.msg._raw_message[:5]
|
||||||
super().__init__(f"SendMessage-{self.msg.id}-{name}")
|
super().__init__(f"TXPKT-{self.msg.id}-{name}")
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
"""Loop until a message is acked or it gets delayed.
|
"""Loop until a message is acked or it gets delayed.
|
||||||
@ -395,7 +400,7 @@ class SendMessageThread(threads.APRSDThread):
|
|||||||
# tracking the time.
|
# tracking the time.
|
||||||
log_message(
|
log_message(
|
||||||
"Sending Message",
|
"Sending Message",
|
||||||
str(msg).rstrip("\n"),
|
str(msg),
|
||||||
msg.message,
|
msg.message,
|
||||||
tocall=self.msg.tocall,
|
tocall=self.msg.tocall,
|
||||||
retry_number=msg.last_send_attempt,
|
retry_number=msg.last_send_attempt,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user