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

Json encode log objects instead of printing a multiline string #113

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

dbhynds
Copy link
Member

@dbhynds dbhynds commented Nov 28, 2023

Summary of Changes

Currently when we log requests, it's spits out a nasty multi-line logs for the response object that are impossible to read in stackdriver. Example:

[28-Nov-2023 15:13:42 UTC] Getting lineitems: Array
(
    [request_method] => GET
    [request_url] => https://canvas.localhost/api/lti/courses/13/line_items
    [response_headers] => Array
        (
            [Server] => nginx/1.25.2
            [Date] => Tue, 28 Nov 2023 15:13:42 GMT
            [Content-Type] => application/vnd.ims.lis.v2.lineitemcontainer+json; charset=utf-8
            [Transfer-Encoding] => chunked
            [Connection] => keep-alive
            [Status] => 200 OK
            [X-Request-Cost] => 0.06348237000029755
            [Cache-Control] => max-age=0, private, must-revalidate
            [X-Request-Context-Id] => 0ba25001-7296-4114-985d-12ced8ef7d53
            [Strict-Transport-Security] => max-age=31536000
            [Referrer-Policy] => no-referrer-when-downgrade
            [X-Rate-Limit-Remaining] => 600.0
            [X-Permitted-Cross-Domain-Policies] => none
        )
)

This changes it to json-encode the object, which is more developer friendly and puts everything on a single line. Here's the result:

[28-Nov-2023 15:13:42 UTC] Getting lineitems: { "request_method": "GET", "request_url": "https://canvas.localhost/api/lti/courses/13/line_items", "response_headers": { "Server": "nginx/1.25.2", "Date": "Tue, 28 Nov 2023 15:13:42 GMT", "Content-Type": "application/vnd.ims.lis.v2.lineitemcontainer+json; charset=utf-8", "Transfer-Encoding": "chunked", "Connection": "keep-alive", "Status": "200 OK", "X-Request-Cost": "0.06348237000029755", "Cache-Control": "max-age=0, private, must-revalidate", "X-Request-Context-Id": "0ba25001-7296-4114-985d-12ced8ef7d53", "Strict-Transport-Security": "max-age=31536000", "Referrer-Policy": "no-referrer-when-downgrade", "X-Rate-Limit-Remaining": "600.0", "X-Permitted-Cross-Domain-Policies": "none" }}

Testing

  • I have added automated tests for my changes
  • I ran composer test before opening this PR
  • I ran composer lint-fix before opening this PR

Copy link

@lin-brian-l lin-brian-l left a comment

Choose a reason for hiding this comment

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

Great change, this was very annoying 🔥

@dbhynds dbhynds merged commit d8072aa into master Nov 28, 2023
3 checks passed
@dbhynds dbhynds deleted the log-as-json branch November 28, 2023 17:39
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.

2 participants