AWS Glue Python ETL:错误 cloudwatch 流中出现记录器消息
AWS Glue Python ETL: logger messages appear in the error cloudwatch stream
我正在编写一个 Glue ETL,我正在尝试使用 Python 默认值 logger
进行记录。
问题是我使用记录器打印的所有日志消息都出现在作业的错误流中。
如果我直接打印到标准输出(使用 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))
到我的记录器定义。
这解决了问题
我正在编写一个 Glue ETL,我正在尝试使用 Python 默认值 logger
进行记录。
问题是我使用记录器打印的所有日志消息都出现在作业的错误流中。
如果我直接打印到标准输出(使用 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))
到我的记录器定义。 这解决了问题