Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,10 @@ timestamp:::date-rfc3339, HOSTNAME, app-name, procid, msgid, msg and structured-

For example the rfc3164 log format would be defined as `<%pri%>%timestamp% %HOSTNAME% %app-name%[%procid%]: %msg%`

``truncate_multiline`` (default ``true``)
``octet_counted_framing`` (default ``false``)

By default, log messages are sent using non-transparent framing and are terminated by newline.
Set it to ``false`` if the server supports octet-counted framing and messages are multi-line.
Set it to ``true`` if the server supports octet-counted framing and messages are multi-line.
(see `RFC 6587 for Syslog over TCP message transfer <https://datatracker.ietf.org/doc/html/rfc6587#section-3.4.1>`_)

``structured_data`` (default ``null``)
Expand Down
15 changes: 8 additions & 7 deletions journalpump/rsyslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def __init__(
keyfile=None,
certfile=None,
log_format=None,
truncate_multiline=None,
octet_counted_framing=None,
):
self.socket = None
self.server = server
self.port = port
self.max_msg = max_msg or 2048
self.socket_proto = socket.SOCK_STREAM
self.ssl_context = None
self.truncate_multiline = True if truncate_multiline is None else truncate_multiline
self.octet_counted_framing = False if octet_counted_framing is None else octet_counted_framing
if rfc == "RFC5424":
self.formatter = _rfc_5424_formatter
elif rfc == "RFC3164":
Expand Down Expand Up @@ -161,12 +161,13 @@ def send(self, message):
# length and a space (<length> <message>).
# - Non-transparent framing: Each message is terminated by a
# newline (\n).
# So far, non-transparent framing was used by journalpump,
# and multi-line log messages were truncated to 1st line.
# So far, only non-transparent framing was used by journalpump
# and multi-line log messages were terminated at first newline.
# We keep this behavior by default, but now expose a new config
# allowing to switch to octet-counted framing, so that
# multi-line log messages only get truncated by max size.
if not self.truncate_multiline:
# allowing to switch to octet-counted framing. Provided that this
# method is supported by the syslog server, multi-line messages
# will only get truncated according to the max_message_size.
if self.octet_counted_framing:
message = f"{len(message)} ".encode("utf-8") + message

self.socket.sendall(message[: self.max_msg - 1])
Expand Down
2 changes: 1 addition & 1 deletion journalpump/senders/rsyslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _init_rsyslog_client(self):
keyfile=self.config.get("client_key"),
certfile=self.config.get("client_cert"),
log_format=self.config.get("logline"),
truncate_multiline=self.config.get("truncate_multiline"),
octet_counted_framing=self.config.get("octet_counted_framing"),
)
self.log.info(
"Initialized Rsyslog Client %s, server: %s, port: %d",
Expand Down
12 changes: 6 additions & 6 deletions systest/test_rsyslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _run_pump_test(


@pytest.mark.parametrize(
"messages_to_send,truncate_multiline_config,expected_message_count,expected_multiline_support",
"messages_to_send,octet_counted_framing_config,expected_message_count,expected_multiline_support",
[
(
[
Expand All @@ -189,7 +189,7 @@ def _run_pump_test(
"PRIORITY": journal.LOG_CRIT,
},
],
{}, # config not specified, truncate_multiline is True by default
{}, # config not specified, octet_counted_framing is False by default
4,
False,
),
Expand All @@ -200,7 +200,7 @@ def _run_pump_test(
"PRIORITY": journal.LOG_INFO,
},
],
{"truncate_multiline": True},
{"octet_counted_framing": False},
1,
False,
),
Expand All @@ -211,7 +211,7 @@ def _run_pump_test(
"PRIORITY": journal.LOG_INFO,
},
],
{"truncate_multiline": False},
{"octet_counted_framing": True},
1,
True,
),
Expand All @@ -220,7 +220,7 @@ def _run_pump_test(
def test_rsyslogd_tcp_sender(
tmpdir,
messages_to_send,
truncate_multiline_config,
octet_counted_framing_config,
expected_message_count,
expected_multiline_support,
):
Expand All @@ -239,7 +239,7 @@ def test_rsyslogd_tcp_sender(
"rsyslog_port": 5140,
"format": "custom",
"logline": "<%pri%>%timestamp% %HOSTNAME% %app-name%[%procid%]: %msg% {%%} %not-valid-tag%",
**dict(truncate_multiline_config),
**dict(octet_counted_framing_config),
},
},
},
Expand Down