简体   繁体   English

如何在使用AWS Lambda时限制来自Cloudwatch的不需要的日志?

[英]How to restrict unwanted logs from Cloudwatch while using AWS Lambda?

I have a lambda function that reads file from S3 bucket and stores it to another S3 bucket. 我有一个lambda函数,它从S3存储桶读取文件并将其存储到另一个S3存储桶。 The lambda is working fine, but when I see the cloudwatch for logs, I see additional logs which is not needed. lambda运行正常,但当我看到cloudwatch的日志时,我看到了不需要的其他日志。

The additional logs that I get are like below., 我得到的其他日志如下所示。

[main] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext 
[main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
[main] DEBUG com.amazonaws.AmazonWebServiceClient
[main] DEBUG org.apache.http.headers
[main] DEBUG org.apache.http.wire

I want to display only the logger.info() used inside the code to be displayed in cloudwatch. 我想只显示在cloudwatch中显示的代码中使用的logger.info() Is there any way to restrict those logs from getting displayed ? 有没有办法限制这些日志显示? Can someone provide an example code for reference ? 有人可以提供示例代码供参考吗?

I am setting log4j.properties file, with the below content. 我正在设置log4j.properties文件,其中包含以下内容。

log4j.rootLogger=INFO
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c -  %m%n
# Log all HTTP content (headers, parameters, content, etc)  for
# all requests and responses. Use caution with this since it can
# be very expensive to log such verbose data!
log4j.logger.org.apache.http.wire=INFO

This is a Log4J 1.x logging configuration, so the way to eliminate unwanted messages is: 这是Log4J 1.x日志记录配置,因此消除不需要的消息的方法是:

  1. Change the root logger to only allow important messages (you could set it to OFF , but you really want to see errors wherever they occur): 将根记录器更改为仅允许重要消息(您可以将其设置为OFF ,但您确实希望在出现错误的地方看到错误):

    log4j.rootLogger=ERROR

  2. Change the logger for your application to enable logging: 更改应用程序的记录器以启用日志记录:

    log4j.logger.com.example.myprogram=INFO

If you have multiple packages that you want to display, you need to set their logging configuration individually. 如果要显示多个程序包,则需要单独设置其日志记录配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM