aws / aws-lambda-runtime-interface-emulator

Apache License 2.0
921 stars 95 forks source link

env var to set loglevel for python logging #41

Open barakbd opened 3 years ago

barakbd commented 3 years ago

Is there a way to set the loglevel through an env var? This would be especially useful for lambda-docker. We would like to be able to filter out a lot of noise and only see our app logs, at least during development.

ghost commented 2 years ago

Thank you for the suggestion barakbd.

It seems the default log level environment variable name in Go is LOG_LEVEL, is that what you would expect?

ghost commented 2 years ago

Thank you @barakbd for this suggestion.

We have merged functionality upstream to enable the providing of the log level via the environment variable LOG_LEVEL.

This functionality will be available with the next merge from upstream. I will leave this ticket open until the next merge from upstream.

Thanks you!

jcampbell05 commented 1 year ago

Has this been merge, I'm trying to debug why the RIE exits with a 0 code but I'm currently getting no logs to explain why.

LOG_LEVEL=DEBUG

Has no effect

ghost commented 1 year ago

@jcampbell05 Sorry for the confusion.

No this functionality is not currently within this open sourced code base. This is why I have left the ticket open.

This has been merged into the upstream repository within Amazon and the functionality will be made available upon the next synchronisation from Amazon's upstream repository.

How are running your Lambda locally?

jcampbell05 commented 1 year ago

We are currently using a Custom Container Image built on the Docker Hub Node image and followed the instructions in the documentation to download the emulator, install the Node runtime and run a ./entry.sh script

The runtime is working but currently the emulator exits immediately with a code 0 which from the code looks like what it does whenever it needs to shutdown but it currently fails to log any contextual information on why it's shutting down.

ghost commented 1 year ago

You can modify the entry.sh script to pass the log level as a command line argument, while waiting on being able to pass it as an environment variable to be synchronised.

E.g.

#!/bin/sh

if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then 
    exec /usr/local/bin/aws-lambda-rie /usr/bin/npx aws-lambda-ric --log-level "trace"
else 
    exec /usr/bin/npx aws-lambda-ric
fi

You can see this is something AWS SAM would do on your behalf[1] if you were using it.

jcampbell05 commented 1 year ago

So I've added that flag and unfortunately it still just exits with a code 0 with no logs at all. I'll check out SAM but we already have an existing setup based around the serverless framework

jcampbell05 commented 1 year ago

In the end it turns out I was forgetting to tell curl to follow redirects and it was downloading an empty binary which in turn was being executed without any errors by the container instead of a invalid format error as I assume it was being treated as an empty executable shell script.

More details here: https://github.com/nodejs/docker-node/issues/1812

But please disregard my earlier comments.