I have AWS Lambdas coded using Java8. I am using Log4j1.2.17 for logging needs:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
The logging configuration is specified using log4.properties file as follows:
# Root logger option
log4j.rootLogger=INFO, stdout
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
As you can see currently the log level is set to "info". i want to change log level using the AWS Lambda environment variables such that if Debug is needed, set some Lambda environment variable and it should be reflected in Lambda function so that it starts logging in Debug statements. Any help will be appreciated. Thanks
If you could migrate to Log4j2 (which is currently supported by AWS Lambda, you can find details on AWS GitHub), there is the "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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With