Skip to content

Commit

Permalink
Fix stale comments in logger.rs (#10695)
Browse files Browse the repository at this point in the history
Some of the comments are stale post #10686.

[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Aug 28, 2020
1 parent 39d71bc commit fb7cb5d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
9 changes: 3 additions & 6 deletions src/python/pants/init/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
19 changes: 5 additions & 14 deletions src/rust/engine/logging/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}

Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/rust/engine/src/externs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,6 @@ fn init_logging(

fn setup_pantsd_logger(py: Python, log_file: String) -> CPyResult<i64> {
logging::set_thread_destination(Destination::Pantsd);

let path = PathBuf::from(log_file);
PANTS_LOGGER
.set_pantsd_logger(path)
Expand Down

0 comments on commit fb7cb5d

Please sign in to comment.