From 066220454f701db60519dc3fc2bcc6a3c443d1a7 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Sun, 19 Apr 2020 10:44:08 +0200 Subject: [PATCH] Add disable_existing_logger:False to logging config, to prevent suppressing logging messages from loggers that haven't been explicitly declared (#1337) --- locust/log.py | 1 + locust/test/test_log.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/locust/log.py b/locust/log.py index 79e27e4c55..00b4170639 100644 --- a/locust/log.py +++ b/locust/log.py @@ -14,6 +14,7 @@ def setup_logging(loglevel, logfile=None): LOGGING_CONFIG = { "version": 1, + "disable_existing_loggers": False, "formatters": { "default": { "format": "[%(asctime)s] {0}/%(levelname)s/%(name)s: %(message)s".format(HOSTNAME), diff --git a/locust/test/test_log.py b/locust/test/test_log.py index 33517f6231..e6cc9fc8bb 100644 --- a/locust/test/test_log.py +++ b/locust/test/test_log.py @@ -38,12 +38,15 @@ def test_logging_output(self): import logging from locust import Locust, task, constant + custom_logger = logging.getLogger("custom_logger") + class MyLocust(Locust): wait_time = constant(2) @task def my_task(self): print("running my_task") logging.info("custom log message") + custom_logger.info("test") """)) as file_path: output = subprocess.check_output([ "locust", @@ -75,6 +78,11 @@ def my_task(self): "%s/INFO/root: custom log message" % socket.gethostname(), output, ) + # check that custom message of custom_logger is also printed + self.assertIn( + "%s/INFO/custom_logger: test" % socket.gethostname(), + output, + ) def test_skip_logging(self): with temporary_file(textwrap.dedent("""