我正在编写一个 Glue ETL,并且我正在尝试使用 Python 默认的 logger
进行记录。
问题是我使用记录器打印的所有日志消息都出现在作业的错误流中。
如果我直接打印到 stdout(使用 print
),我会在常规 cloudwatch 日志流中看到打印的消息。
我尝试将记录器重定向到标准输出,但仍然得到相同的结果:消息出现在错误流中。
有谁知道我如何使用记录器,并且仍然在日志cloudwatch流中看到我的消息? (并且不在错误的cloudwatch流中)
这是我用来测试的代码示例:
import logging
import sys
MSG_FORMAT = '%(asctime)s %(levelname)s %(name)s: %(message)s'
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
logging.basicConfig(format=MSG_FORMAT, datefmt=DATETIME_FORMAT, stream=sys.stdout)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.info("Test log message. This appear on the job error cloudwatch stream")
print("This is a print. This appear on the job log cloudwatch stream")
最佳答案
我最终添加了
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
到我的记录器定义。 问题就这样解决了
关于python - AWS Glue Python ETL : logger messages appear in the error cloudwatch stream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62174436/