Skip to main content
Version: 2.25 (dev)

Logging and dynamic output

How to add logging and influence the dynamic UI.


Even though a @goal_rule is the only type of rule that can print to stdout (via the special Console type), any rule can log to stderr and change how the rule appears in the dynamic UI.

Adding logging

To add logging, use the logging standard library module.

import logging

logger = logging.getLogger(__name__)

@rule
def demo(...) -> Foo:
logger.info("Inside the demo rule.")
...

You can use logger.info, logger.warning, logger.error, logger.debug, and logger.trace. You can then change your log level by setting the -l/--level option, e.g. pants -ldebug my-goal.

Changing the dynamic UI

Streaming results (advanced)

When you run pants fmt, pants lint, and pants test, you may notice that we "stream" the results. As soon as an individual process finishes, we print the result, rather than waiting for all the processes to finish and dumping at the end.

We also set the log level dynamically. If something succeeds, we log the result at INFO, but if something fails, we use WARN.