theam / aws-lambda-haskell-runtime

⚡Haskell runtime for AWS Lambda
https://theam.github.io/aws-lambda-haskell-runtime/
Other
270 stars 48 forks source link

Question: How do I log from a Lambda #52

Closed pparkkin closed 4 years ago

pparkkin commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Definitely. I'll take a look.

pparkkin commented 4 years ago

https://github.com/theam/aws-lambda-haskell-runtime/pull/53

NickSeagull commented 4 years ago

Thanks!

pparkkin commented 4 years ago

Thanks for accepting the fix!

NickSeagull commented 4 years ago

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! 🙏