diff --git a/src/python/pants/init/logging.py b/src/python/pants/init/logging.py index 9dda2ffbd79..17c66bc535f 100644 --- a/src/python/pants/init/logging.py +++ b/src/python/pants/init/logging.py @@ -26,17 +26,14 @@ def init_rust_logger(log_level: LogLevel, log_show_rust_3rdparty: bool, use_colo class NativeHandler(StreamHandler): - """This class is installed as a Python logging module handler (using the logging.addHandler + """This class is installed as a Python logging module handler (using the logging.addHandler method) and proxies logs to the Rust logging infrastructure.""" - def __init__( - self, log_level: LogLevel, native_filename: Optional[str] = None, - ): + def __init__(self, log_level: LogLevel, native_filename: Optional[str] = None) -> None: super().__init__(None) self.native = Native() self.native_filename = native_filename self.setLevel(log_level.level) - if not self.native_filename: self.native.setup_stderr_logger() @@ -102,7 +99,7 @@ def trace_fn(self, message, *args, **kwargs): def setup_logging(global_bootstrap_options): - """Sets up logging for a pants run. + """Sets up logging for a Pants run. This is called in two contexts: 1) PantsRunner, 2) DaemonPantsRunner. In the latter case, the loggers are saved and restored around this call, so in both cases it runs with no handlers diff --git a/src/rust/engine/logging/src/logger.rs b/src/rust/engine/logging/src/logger.rs index 84a8e1c93fb..9579eca934d 100644 --- a/src/rust/engine/logging/src/logger.rs +++ b/src/rust/engine/logging/src/logger.rs @@ -62,10 +62,7 @@ impl PantsLogger { }; } - /// - /// Set up a file logger which logs at python_level to log_file_path. - /// Returns the file descriptor of the log file. - /// + /// Set up a file logger to log_file_path. Returns the file descriptor of the log file. #[cfg(unix)] pub fn set_pantsd_logger( &self, @@ -95,12 +92,9 @@ impl PantsLogger { /// function, which translates the log message into the Rust log paradigm provided by /// the `log` crate. pub fn log_from_python(message: &str, python_level: u64, target: &str) -> Result<(), String> { - python_level - .try_into() - .map_err(|err| format!("{}", err)) - .map(|level: PythonLogLevel| { - log!(target: target, level.into(), "{}", message); - }) + let level: PythonLogLevel = python_level.try_into().map_err(|err| format!("{}", err))?; + log!(target: target, level.into(), "{}", message); + Ok(()) } pub fn register_stderr_handler(&self, callback: StdioHandler) -> Uuid { @@ -118,9 +112,6 @@ impl PantsLogger { impl Log for PantsLogger { fn enabled(&self, metadata: &Metadata) -> bool { - // Individual log levels are handled by each sub-logger, - // And a global filter is applied to set_max_level. - // No need to filter here. metadata.level() <= max_level() } @@ -150,7 +141,7 @@ impl Log for PantsLogger { let time_str = format!( "{}.{:02}", cur_date.format(TIME_FORMAT_STR), - cur_date.time().nanosecond() / 10_000_000 // two decimal places of precision + cur_date.time().nanosecond() / 10_000_000 // Two decimal places of precision. ); let level = record.level(); diff --git a/src/rust/engine/src/externs/interface.rs b/src/rust/engine/src/externs/interface.rs index 691ae0dfe4c..ab594387158 100644 --- a/src/rust/engine/src/externs/interface.rs +++ b/src/rust/engine/src/externs/interface.rs @@ -1671,7 +1671,6 @@ fn init_logging( fn setup_pantsd_logger(py: Python, log_file: String) -> CPyResult { logging::set_thread_destination(Destination::Pantsd); - let path = PathBuf::from(log_file); PANTS_LOGGER .set_pantsd_logger(path)