def test_log_filtering_by_rule() -> None: with temporary_dir() as tmpdir: ob = create_options_bootstrapper([ f"--pants-workdir={tmpdir}", '--log-levels-by-target={"debug_target": "debug"}' ]) # Do not set up a stdio destination, meaning that all messages will go to the log. global_bootstrap_options = ob.bootstrap_options.for_global_scope() with initialize_stdio(global_bootstrap_options): native_engine.write_log(msg="log msg one", level=LogLevel.INFO.level, target="some.target") native_engine.write_log(msg="log msg two", level=LogLevel.DEBUG.level, target="some.other.target") native_engine.write_log(msg="log msg three", level=LogLevel.DEBUG.level, target="debug_target") loglines = (Path(global_bootstrap_options.pants_workdir, "pants.log").read_text().splitlines()) assert "[INFO] log msg one" in loglines[0] assert "[DEBUG] log msg three" in loglines[1] assert len(loglines) == 2
def emit(self, record: LogRecord) -> None: native_engine.write_log(msg=self.format(record), level=record.levelno, target=record.name)
def emit(self, record: LogRecord) -> None: native_engine.write_log(self.format(record), record.levelno, record.name)