我正在尝试使用 Python 为我的 AWS Glue 作业设置一个记录器logging
模块。我有一个使用 Python 版本 3 的类型为“Python Shell”的 Glue 作业。
如果我实例化记录器而没有任何记录,则记录工作正常name
,但是如果我给我的记录器一个name
,它不再起作用,并且我收到一条错误消息:Log stream not found
.
我在示例胶水作业中有以下代码:
import sys
import logging
# Version 1 - this works fine
logger = logging.getLogger()
log_format = "[%(asctime)s %(levelname)-8s %(message)s"
# Version 2 - this fails
logger = logging.getLogger(name = "foobar")
log_format = "[%(name)s] %(asctime)s %(levelname)-8s %(message)s"
date_format = "%a, %d %b %Y %H:%M:%S %Z"
log_stream = sys.stdout
if logger.handlers:
for handler in logger.handlers:
logger.removeHandler(handler)
logging.basicConfig(level = logging.INFO, format = log_format, stream =
log_stream, datefmt = date_format)
logger.info("This is a test.")
请注意,我将根据以下内容删除处理程序this https://forums.aws.amazon.com/thread.jspa?threadID=288743 post.
如果我使用代码版本 1 实例化记录器,它会成功运行,并且我能够查看日志并在CloudWatch
.
如果我运行版本 2,并为记录器指定名称,Glue 作业仍然会成功。但是,如果我尝试查看日志,则会收到以下错误消息:
Log stream not found
The log stream jr_f137743545d3d242618ac95d859b9146fd15d15a0aadce64d8f3ba991ffed012 could not be found. Check if it was correctly created and retry.
而且我也无法查询这些日志CloudWatch
.
我尝试使用 python 版本在本地运行此代码3.6.0
,并且两个版本都可以工作。此外,此日志记录代码的两个版本都在 Lambda 函数内部工作。他们只在胶水方面失败了。