Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit multi-line logs with timestamps #92

Merged
merged 4 commits into from Feb 16, 2023
Merged

Emit multi-line logs with timestamps #92

merged 4 commits into from Feb 16, 2023

Conversation

thenewguy39
Copy link

Description of changes:
Lambda accepts multi-line messages where the timestamp of the log emission is encoded in the log event header. This helps ordering the function emitted messages with regards to platform emitted messages, e.g. START, REPORT.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@luben
Copy link

luben commented Jan 18, 2023

LGTM

@@ -1027,6 +1046,7 @@ def test_log_error_invokeId_line_framed_log_sink(self):
"testrequestId",
)
bootstrap.log_error(err_to_log, log_sink)
after = int(time.time_ns() / 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: adding randomness into unit tests is discouraged. In this particular case it should not cause losing determinism, so it's fine to leave if here

awslambdaric/bootstrap.py Show resolved Hide resolved
@@ -335,7 +335,8 @@ def __exit__(self, exc_type, exc_value, exc_tb):

def log(self, msg):
encoded_msg = msg.encode("utf8")
log_msg = self.frame_type + len(encoded_msg).to_bytes(4, "big") + encoded_msg
timestamp = int(time.time_ns() / 1000) # UNIX timestamp in microseconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using // should be a cleaner way to show that it's not a type conversion

@briensea briensea merged commit 97dee25 into aws:main Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants