如何在 Locust 中配置日志记录?

How can I configure logging in Locust?

使用 locust 1.4.1 and the documentation that talks about logging (here) 提到我可以使用 --skip-log-setup 选项提供我自己的日志记录配置。

我的问题是:

我的代码有自己的记录器,但我想要 想要 stdout 中的蝗虫记录器(目前我的记录器同时进入 stdout 和文件)。我想从我的代码中删除标准输出记录器:

locust -f <my_file.py> --headless

然后在 Locust 文件中:

import logging
from locust import HttpUser
import my_class  # 'MyLogger' defined here with 2 handlers: file and stdout

my_logger = logging.getLogger('MyLogger')
handler = logging.handlers[1]  # 0 is file, 1 is stdout, but comes back as []!


class MyTest(HttpUser):
  blah

希望这是有道理的。如果需要澄清,请告诉我。

好的,找到了适合我需要的东西。

运行 Locust --skip-log-setup,这将使 Locust 没有任何日志记录。

locust -f my_file.py --headless --skip-log-setup <other params>

然后在测试文件中:

# Set root logging
logging.getLogger().setLevel('DEBUG')

# Add stdout to locust logging
logger = logging.getLogger('locust')
logger.addHandler(logging.StreamHandler(sys.stdout))