how can I view the logs generated from pants while...
# plugins
f
how can I view the logs generated from pants while testing my plugin? I’ve tried setting
-ldebug
,
--logdir
and
--keep-sandboxes=always
via
rule_runner.set_options
but haven’t actually been able to find the logs
b
I’m on mobile, so can’t help a lot… but two things I would try are: 1. Use the pytest caplog fixture 2. search in the pants code base for tests that do something with logging and see how its handled there (all test files end with
_test.py
)
f
thanks! adding the caplog and increasing the log level was enough for me to debug
Copy code
def test_foo(rule_runner: RuleRunner, caplog) -> None:
    caplog.set_level(logging.DEBUG)
c
when writing tests that use the
RuleRunner
, decorating your test with
pantsbuild.testutil.rule_runner.logging
is usually also helpful: https://github.com/pantsbuild/pants/blob/ef0352086e1290c0ebf73808d2fd5fc4aa37d96e/src/python/pants/testutil/rule_runner.py#L74-L92
👍 1
f
oh nice, looks like that provides all the logs, while the caplog version only captures a subset
👍 1