Skip to content

Commit

Permalink
Split messages by max limit so that the AWS can accept the log event
Browse files Browse the repository at this point in the history
  • Loading branch information
vimleshtna committed Dec 5, 2024
1 parent b1460dd commit d81512a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions .github/scripts/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
log_group_name = sys.argv[3]
log_stream_name = sys.argv[2]


def split_message(s, length):
for i in range(0, len(s), length):
yield s[i:i + length]


log_event = []
with open(sys.argv[1]) as file:
message = file.read()
if len(message.encode("utf-8")) > 262144:
message_list = message.split("\n")
mid_point = len(message_list) // 2
first_half = "\n".join(message_list[0: mid_point])
second_half = "\n".join(message_list[mid_point:])
log_event = [{'timestamp': timestamp, 'message': first_half}, {'timestamp': timestamp, 'message': second_half}]
for chunk in split_message(message, 262140):
log_event.append({'timestamp': timestamp, 'message': chunk})
else:
log_event = [{'timestamp': timestamp, 'message': message}]

Expand All @@ -30,6 +34,5 @@
fragment = f"logsV2:log-groups/log-group/{log_group_name}/log-events/{encoded_stream_name}"
url = f"{base_url}?region=eu-west-2#{fragment}"


with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f"log-url={url}", file=fh)

0 comments on commit d81512a

Please sign in to comment.