AWS Glue Python ETL:记录器消息出现在错误cloudwatch流中

2024-04-25 20:02:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个Glue ETL,并尝试使用Python默认的logger进行日志记录

问题是,我正在使用记录器打印的所有日志消息都出现在作业的错误流中

如果我直接打印到stdout(使用print),我会在常规cloudwatch日志流中看到打印的消息

我试图将日志重定向到标准输出,但仍然得到相同的结果:错误流中出现消息

有人知道我如何使用logger,并且仍然可以在log 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")

Tags: importlogformat消息messagestreamlogging错误

热门问题