コード例 #1
0
  def _pantsd_logging(self):
    """A context manager that runs with pantsd logging.

    Asserts that stdio (represented by file handles 0, 1, 2) is closed to ensure that
    we can safely reuse those fd numbers.
    """

    # Ensure that stdio is closed so that we can safely reuse those file descriptors.
    for fd in (0, 1, 2):
      try:
        os.fdopen(fd)
        raise AssertionError(
            'pantsd logging cannot initialize while stdio is open: {}'.format(fd))
      except OSError:
        pass

    # Redirect stdio to /dev/null for the rest of the run, to reserve those file descriptors
    # 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, self._log_show_rust_3rdparty)
      result = setup_logging(self._log_level, log_dir=self._log_dir, log_name=self.LOG_NAME, native=self._native)
      self._native.override_thread_logging_destination_to_just_pantsd()

      # Do a python-level redirect of stdout/stderr, which will not disturb `0,1,2`.
      # TODO: Consider giving these pipes/actual fds, in order to make them "deep" replacements
      # for `1,2`, and allow them to be used via `stdio_as`.
      sys.stdout = _LoggerStream(logging.getLogger(), logging.INFO, result.log_handler)
      sys.stderr = _LoggerStream(logging.getLogger(), logging.WARN, result.log_handler)

      self._logger.debug('logging initialized')
      yield (result.log_handler.stream, result.log_handler.native_filename)
コード例 #2
0
ファイル: pants_daemon.py プロジェクト: jsirois/pants
  def _pantsd_logging(self):
    """A context manager that runs with pantsd logging.

    Asserts that stdio (represented by file handles 0, 1, 2) is closed to ensure that
    we can safely reuse those fd numbers.
    """

    # Ensure that stdio is closed so that we can safely reuse those file descriptors.
    for fd in (0, 1, 2):
      try:
        os.fdopen(fd)
        raise AssertionError(
            'pantsd logging cannot initialize while stdio is open: {}'.format(fd))
      except OSError:
        pass

    # Redirect stdio to /dev/null for the rest of the run, to reserve those file descriptors
    # 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, self._log_show_rust_3rdparty)
      result = setup_logging(self._log_level, log_dir=self._log_dir, log_name=self.LOG_NAME, native=self._native)
      self._native.override_thread_logging_destination_to_just_pantsd()

      # Do a python-level redirect of stdout/stderr, which will not disturb `0,1,2`.
      # TODO: Consider giving these pipes/actual fds, in order to make them "deep" replacements
      # for `1,2`, and allow them to be used via `stdio_as`.
      sys.stdout = _LoggerStream(logging.getLogger(), logging.INFO, result.log_handler)
      sys.stderr = _LoggerStream(logging.getLogger(), logging.WARN, result.log_handler)

      self._logger.debug('logging initialized')
      yield (result.log_handler.stream, result.log_handler.native_filename)
コード例 #3
0
    def _pantsd_logging(self) -> Iterator[IO[str]]:
        """A context manager that runs with pantsd logging.

        Asserts that stdio (represented by file handles 0, 1, 2) is closed to ensure that we can
        safely reuse those fd numbers.
        """

        # Ensure that stdio is closed so that we can safely reuse those file descriptors.
        for fd in (0, 1, 2):
            try:
                os.fdopen(fd)
                raise AssertionError(
                    f"pantsd logging cannot initialize while stdio is open: {fd}"
                )
            except OSError:
                pass

        # Redirect stdio to /dev/null for the rest of the run, to reserve those file descriptors
        # 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, self._log_show_rust_3rdparty)
            # We can't statically prove it, but we won't execute `launch()` (which
            # calls `run_sync` which calls `_pantsd_logging`) unless PantsDaemon
            # is launched with full_init=True. If PantsdDaemon is launched with
            # full_init=True, we can guarantee self._native and self._bootstrap_options
            # are non-None.
            native = cast(Native, self._native)
            bootstrap_options = cast(OptionValueContainer,
                                     self._bootstrap_options)

            level = self._log_level
            ignores = bootstrap_options.for_global_scope(
            ).ignore_pants_warnings
            clear_previous_loggers()
            setup_logging_to_stderr(level, warnings_filter_regexes=ignores)
            log_dir = os.path.join(self._work_dir, self.name)
            log_handler = setup_logging_to_file(
                level,
                log_dir=log_dir,
                log_filename=self.LOG_NAME,
                warnings_filter_regexes=ignores)

            native.override_thread_logging_destination_to_just_pantsd()

            # Do a python-level redirect of stdout/stderr, which will not disturb `0,1,2`.
            # TODO: Consider giving these pipes/actual fds, in order to make them "deep" replacements
            # for `1,2`, and allow them to be used via `stdio_as`.
            sys.stdout = _LoggerStream(logging.getLogger(), logging.INFO,
                                       log_handler)  # type: ignore[assignment]
            sys.stderr = _LoggerStream(logging.getLogger(), logging.WARN,
                                       log_handler)  # type: ignore[assignment]

            self._logger.debug("logging initialized")
            yield log_handler.stream
コード例 #4
0
ファイル: pants_daemon.py プロジェクト: matze999/pants
    def _pantsd_logging(self) -> Iterator[IO[str]]:
        """A context manager that runs with pantsd logging.

        Asserts that stdio (represented by file handles 0, 1, 2) is closed to ensure that we can
        safely reuse those fd numbers.
        """

        # Ensure that stdio is closed so that we can safely reuse those file descriptors.
        for fd in (0, 1, 2):
            try:
                os.fdopen(fd)
                raise AssertionError(
                    f"pantsd logging cannot initialize while stdio is open: {fd}"
                )
            except OSError:
                pass

        # Redirect stdio to /dev/null for the rest of the run, to reserve those file descriptors
        # for further forks.
        with stdio_as(stdin_fd=-1, stdout_fd=-1, stderr_fd=-1):
            # Reinitialize logging for the daemon context.
            use_color = self._bootstrap_options.for_global_scope().colors
            init_rust_logger(self._log_level,
                             self._log_show_rust_3rdparty,
                             use_color=use_color)

            level = self._log_level
            ignores = self._bootstrap_options.for_global_scope(
            ).ignore_pants_warnings
            clear_logging_handlers()
            log_dir = os.path.join(self._work_dir, self.name)
            log_handler = setup_logging_to_file(
                level,
                log_dir=log_dir,
                log_filename=self.LOG_NAME,
                warnings_filter_regexes=ignores)

            self._native.override_thread_logging_destination_to_just_pantsd()

            # Do a python-level redirect of stdout/stderr, which will not disturb `0,1,2`.
            # TODO: Consider giving these pipes/actual fds, in order to make them "deep" replacements
            # for `1,2`, and allow them to be used via `stdio_as`.
            sys.stdout = _LoggerStream(logging.getLogger(), logging.INFO,
                                       log_handler)  # type: ignore[assignment]
            sys.stderr = _LoggerStream(logging.getLogger(), logging.WARN,
                                       log_handler)  # type: ignore[assignment]

            self._logger.debug("logging initialized")
            yield log_handler.stream
コード例 #5
0
ファイル: pants_runner.py プロジェクト: zvikihouzz/pants
 def _enable_rust_logging(self, global_bootstrap_options):
     levelname = global_bootstrap_options.level.upper()
     init_rust_logger(levelname,
                      global_bootstrap_options.log_show_rust_3rdparty)
     setup_logging_to_stderr(logging.getLogger(None), levelname)
コード例 #6
0
ファイル: pants_runner.py プロジェクト: tushar19/pants
 def _enable_rust_logging(
         global_bootstrap_options: OptionValueContainer) -> None:
     log_level = global_bootstrap_options.level
     init_rust_logger(log_level,
                      global_bootstrap_options.log_show_rust_3rdparty)
     setup_logging_to_stderr(logging.getLogger(None), log_level)
コード例 #7
0
ファイル: pants_runner.py プロジェクト: cosmicexplorer/pants
 def _enable_rust_logging(self, global_bootstrap_options):
   levelname = global_bootstrap_options.level.upper()
   init_rust_logger(levelname, global_bootstrap_options.log_show_rust_3rdparty)
   setup_logging_to_stderr(logging.getLogger(None), levelname)