Skip to content

Commit

Permalink
Allow 3rdparty rust crate logging to be hidden (pantsbuild#7530)
Browse files Browse the repository at this point in the history
Some crates (particularly gitignore), and particularly at trace level
(tokio) are super verbose (e.g. logging every time the event loop
ticks), which means that in pants we either log everything at debug
level (making debug really verbose), or don't log some things that would
be useful (for fear of it being too verbose).

This enabled-by-default flag hides 3rdparty rust crate logging, enabling
us to log more verbosely at more verbose levels from our own code.
  • Loading branch information
illicitonion authored Apr 16, 2019
1 parent 994751f commit a3f3b0a
Show file tree
Hide file tree
Showing 15 changed files with 575 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/bin/pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, exiter, args=None, env=None, start_time=None):

def _enable_rust_logging(self, global_bootstrap_options):
levelname = global_bootstrap_options.level.upper()
init_rust_logger(levelname)
init_rust_logger(levelname, global_bootstrap_options.log_show_rust_3rdparty)
setup_logging_to_stderr(logging.getLogger(None), levelname)

def run(self):
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/engine/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ def decompress_tarball(self, tarfile_path, dest_dir):
result = self.lib.decompress_tarball(tarfile_path, dest_dir)
return self.context.raise_or_return(result)

def init_rust_logging(self, level):
return self.lib.init_logging(level)
def init_rust_logging(self, level, log_show_rust_3rdparty):
return self.lib.init_logging(level, log_show_rust_3rdparty)

def setup_pantsd_logger(self, log_file_path, level):
log_file_path = log_file_path.encode("utf-8")
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/init/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def _maybe_configure_extended_logging(logger):
_configure_requests_debug_logging()


def init_rust_logger(level):
def init_rust_logger(level, log_show_rust_3rdparty):
native = Native()
levelno = get_numeric_level(level)
native.init_rust_logging(levelno)
native.init_rust_logging(levelno, log_show_rust_3rdparty)


def setup_logging_to_stderr(python_logger, level):
Expand Down
3 changes: 3 additions & 0 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def register_bootstrap_options(cls, register):
register('-q', '--quiet', type=bool, recursive=True, daemon=False,
help='Squelches most console output. NOTE: Some tasks default to behaving quietly: '
'inverting this option supports making them noisier than they would be otherwise.')
register('--log-show-rust-3rdparty', type=bool, default=False, advanced=True,
help='Whether to show/hide logging done by 3rdparty rust crates used by the pants '
'engine.')

# Not really needed in bootstrap options, but putting it here means it displays right
# after -l and -q in help output, which is conveniently contextual.
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/pantsd/pants_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def __init__(self, native, build_root, work_dir, log_level, services,
self._log_level = log_level
self._services = services
self._bootstrap_options = bootstrap_options
self._log_show_rust_3rdparty = bootstrap_options.for_global_scope().log_show_rust_3rdparty if bootstrap_options else True

self._log_dir = os.path.join(work_dir, self.name)
self._logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -306,7 +307,7 @@ def _pantsd_logging(self):
# for further forks.
with stdio_as(stdin_fd=-1, stdout_fd=-1, stderr_fd=-1):
# Reinitialize logging for the daemon context.
init_rust_logger(self._log_level)
init_rust_logger(self._log_level, self._log_show_rust_3rdparty)
result = setup_logging(self._log_level, log_dir=self._log_dir, log_name=self.LOG_NAME, native=self._native)

# Do a python-level redirect of stdout/stderr, which will not disturb `0,1,2`.
Expand Down
Loading

0 comments on commit a3f3b0a

Please sign in to comment.