简体   繁体   English

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

[英]AWS Glue Python ETL: logger messages appear in the error cloudwatch stream

I'm writing a Glue ETL, and I'm trying to log using Python default's logger .我正在编写 Glue ETL,并且正在尝试使用 Python 默认的logger进行记录。

The problem is that all the log messages I'm printing using the logger appear in the error stream of the job.问题是我使用记录器打印的所有日志消息都出现在作业的错误 stream 中。

If I print directly to stdout (using print ), I see the printed messages in the regular cloudwatch log stream.如果我直接打印到标准输出(使用print ),我会在常规 cloudwatch 日志 stream 中看到打印的消息。

I tried to redirect my logger to stdout, but I still got the same result: messages appear in error stream.我试图将我的记录器重定向到标准输出,但我仍然得到相同的结果:消息出现在错误 stream 中。

Does anyone know how I can use logger, and still see my messages in the log cloudwatch stream?有谁知道我如何使用记录器,并且仍然在日志 cloudwatch stream 中看到我的消息? (and not in the error cloudwatch stream) (而不是在错误 cloudwatch 流中)

This is the code sample I'm using to test:这是我用来测试的代码示例:

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")

I ended up adding我最终添加了

logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))

to my logger definition.到我的记录器定义。 That resolved the problem这解决了问题

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

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