title: Is it possible to change the log level of an AWS Lambda at runtime?
body: <p>I'm running a lamba on AWS, and using slf4j for logging</p>
  
  <p>Part of the project requirements is that the log level can be set at runtime, using an environment variable, but I'm not sure if that's possible</p>
  
  <p>I'm using the following code, but changing the environment variable "LOG_LEVEL" in the UI to "DEBUG" has no effect to what is added to the CloudWatch logs. Is this possible?</p>
  
  <pre><code>import org.apache.log4j.Level;
  import org.apache.log4j.LogManager;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  public class MyLambdaHandler implements RequestHandler&lt;Integer, String&gt; {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(MyLambdaHandler.class);
  
      static {
          org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
          String logLevel = (System.getenv("LOG_LEVEL") != null) ? System.getenv("LOG_LEVEL") : "INFO";
          rootLogger.setLevel(Level.toLevel(logLevel));
      }
  
      public String myHandler(int myCount, Context context) {
  
          LOGGER.debug("Entering myHandler lambda handler";
          LOGGER.info("Handling myCount {}", myCount);
          int returnValue = myCount * 2;
          LOGGER.debug("MyHandler return value {}", returnValue);
          return returnValue;
  
      }
  
  }
  </code></pre>