Skip to content

Commit

Permalink
Merge pull request #738 from Exide/skipLogSetup
Browse files Browse the repository at this point in the history
Allow skipping the logging setup
  • Loading branch information
cyberw authored Oct 20, 2019
2 parents 40f64e0 + 9dadbac commit 668b8a3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Locust Documentation
testing-other-systems
api
extending-locust
logging
.. toctree ::
:maxdepth: 4
Expand Down
28 changes: 28 additions & 0 deletions docs/logging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _logging:

=======
Logging
=======

Locust comes with a basic logging configuration that optionally takes ``--loglevel`` and/or ``--logfile`` to modify the configuration. If you want to control the logging configuration you can supply the ``--skip-log-setup`` flag, which ignores the other parameters.

Options
=======

``--skip-log-setup``
--------------------

Disable Locust's logging setup. Instead, the configuration is provided by the Locust test or Python defaults.


``--loglevel``
--------------

Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL. Default is INFO. The short-hand version is ``-L``.


``--logfile``
-------------

Path to log file. If not set, log will go to stdout/stderr.

15 changes: 13 additions & 2 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,16 @@ def parse_options():
'-t', '--run-time',
help="Stop after the specified amount of time, e.g. (300s, 20m, 3h, 1h30m, etc.). Only used together with --no-web"
)


# skip logging setup
parser.add_option(
'--skip-log-setup',
action='store_true',
dest='skip_log_setup',
default=False,
help="Disable Locust's logging setup. Instead, the configuration is provided by the Locust test or Python defaults."
)

# log level
parser.add_argument(
'--loglevel', '-L',
Expand Down Expand Up @@ -362,7 +371,9 @@ def main():
parser, options = parse_options()

# setup logging
setup_logging(options.loglevel, options.logfile)
if not options.skip_log_setup:
setup_logging(options.loglevel, options.logfile)

logger = logging.getLogger(__name__)

locustfile = find_locustfile(options.locustfile)
Expand Down
8 changes: 8 additions & 0 deletions locust/test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def setUp(self):
def test_default(self):
opts = self.parser.parse_args([])
self.assertEqual(opts.reset_stats, False)
self.assertEqual(opts.skip_log_setup, False)

def test_reset_stats(self):
args = [
Expand All @@ -24,3 +25,10 @@ def test_should_accept_legacy_no_reset_stats(self):
]
opts = self.parser.parse_args(args)
self.assertEqual(opts.reset_stats, False)

def test_skip_log_setup(self):
args = [
"--skip-log-setup"
]
opts, _ = self.parser.parse_args(args)
self.assertEqual(opts.skip_log_setup, True)

0 comments on commit 668b8a3

Please sign in to comment.