0

I have aws lambda function implementation using java. I am using the standard log4j configuration to log into cloudwatch . I am able to access the aws lambda environment runtime variable into my log4j to set my log level. The only question I have - Is there a way we can default the log level to something in the absence of the environment variable value in the log4j.xml?

Below is the log4j.xml configuration I have.

< Loggers></br>
    < Root level="debug"><\br>
        < AppenderRef ref="Lambda" /><\br>
    < /Root><\br>
< /Loggers>

1 Answer 1

1

You can migrate to Log4j2 (currently supported by AWS Lambda, you can find details on AWS GitHub), It has "Lookups" feature which allows to use environment variables in Log4j2 configuration file: http://logging.apache.org/log4j/2.x/manual/lookups.html#EnvironmentLookup

So you could use something like this in your configuration file: "${env:VAR_NAME:-info}", where -info would be a default logging level.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.