AWS Lambda login with slf4j

I use a lambda function and write it in Java. I was looking through the log for lambda functions when I was reading documents and they support log4j - http://docs.aws.amazon.com/lambda/latest/dg/java-logging.html#java-wt-logging-using-log4j .

I was wondering if we can use the log using the Slf4j annotation, since Slf4j is only a binding annotation. Has anyone tried using Slf4j before with a lambda?

+5
source share
2 answers

Yes, you can. Just add the following dependencies to your project.

<dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-lambda-java-log4j</artifactId> <version>1.0.0</version> </dependency> 

and create the correct log4j.properties in / src / main / resources / of your project, for example

 log = . log4j.rootLogger = DEBUG, LAMBDA #Define the LAMBDA appender log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout log4j.appender.LAMBDA.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c{1}:%m%n 
+3
source

Just include the following dependency:

 <dependency> <groupId>io.symphonia</groupId> <artifactId>lambda-logging</artifactId> <version>1.0.0</version> </dependency> 

Background information is available at: https://blog.symphonia.io/a-love-letter-to-lambda-logging-974b0eb49273

0
source

Source: https://habr.com/ru/post/1271571/


All Articles