Skip to content

Question: How do I log from a Lambda #52

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

Closed
pparkkin opened this issue Nov 19, 2019 · 8 comments
Closed

Question: How do I log from a Lambda #52

pparkkin opened this issue Nov 19, 2019 · 8 comments

Comments

@pparkkin
Copy link
Contributor

How can I output logs from my handler?

I have been able to create a Lambda using the runtime, and I can return responses that indicate that my handler is being called correctly.

In order to make it easier to develop and debug, I would like to be able to output logs into the CloudWatch logs for the Lambda. If I just do a putStrLn the output is not logged into the CloudWatch log group for the Lambda.

@NickSeagull
Copy link
Contributor

Thanks for reporting in, could you try flushing stdout after your prints? like so:

import System.IO (hFlush, stdout, stderr)

-- your code...
hFlush stdout
hFlush stderr

This needs to be done inside of a do block in an IO-returning function (probably your handler)

@pparkkin
Copy link
Contributor Author

When I flush stdout and stderr, the output goes into CloudWatch logs. Thanks!

Do you think there is something that can be done in the runtime to make output go into logs automatically without having to explicitly flush the handles?

@NickSeagull
Copy link
Contributor

Yes, I just realized that for some reason the runtime is not flushing them. Probably it got lost after #29 .

Would you be up to adding this? It should be relatively simple by flushing after this line

@pparkkin
Copy link
Contributor Author

Definitely. I'll take a look.

@pparkkin
Copy link
Contributor Author

#53

@NickSeagull
Copy link
Contributor

Thanks!

@pparkkin
Copy link
Contributor Author

Thanks for accepting the fix!

@NickSeagull
Copy link
Contributor

Version 2.0.2 with the fix from #53 has been pushed to Hackage now. Closing.

Feel free to reopen if something weird appears. Thanks again! 🙏

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

No branches or pull requests

2 participants