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

Fix: Log ruby stdout to console #1214

Merged
merged 1 commit into from Apr 25, 2021

Conversation

njyjn
Copy link
Contributor

@njyjn njyjn commented Apr 14, 2021

Description

This fix allows stdout to be logged to the console, allowing Ruby output operations like logger.info, puts and p to materialize.

Emulates the way sls invoke local --function ... logs such statements.

Motivation and Context

The use of logger is officially supported by AWS in Lambda, and should produce the same result when running offline. It is also useful to be able to print to console for debugging purposes. The implementation of the Python runner does a similar thing.

Resolves #1206

How Has This Been Tested?

I installed and built the local fork into my project and added the following print statements

def handler(event:, context:)
  logger = Logger.new($stdout)

  logger.info('This is a logger.info message')
  p 'This is a p message'
  puts 'This is a puts message'
  ...

Output was

offline: POST /local/hello (λ: hello)
I, [2021-04-14T16:46:02.387705 #74974]  INFO -- : This is a logger.info message
"This is a p message"
This is a puts message
offline: (λ: hello) RequestId: ckni3qx290005qqku6jww556f  Duration: 831.02 ms  Billed Duration: 832 ms
offline: [200] {"statusCode":200,"body":"{\"message\":\"OK\",\"output\":{\"output\":\"hello\"}}"}```

Built locally using package.json and compiled using Babel per the contribution guide.

Please let me know if you have any questions or if there is something I missed. Thanks!

Screenshots (if appropriate):

@icole
Copy link

icole commented Apr 21, 2021

This is awesome, thanks so much for implementing this. I ran in to this the other day as well and put it on the back burner. Definitely +1 to get this merged 👍

Copy link
Collaborator

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Looks good 👍 Thank you @njyjn 🙇

@pgrzesik pgrzesik merged commit 2d40bc4 into dherault:master Apr 25, 2021
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.

serverless offline with ruby unable to see the log from ruby file
3 participants