Skip to content

Commit

Permalink
Update to latest num_enum (pantsbuild#9344)
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion authored Mar 19, 2020
1 parent 72c4b93 commit 59aa008
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 41 deletions.
54 changes: 47 additions & 7 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ itertools = "0.8.2"
lazy_static = "1"
log = "0.4"
logging = { path = "logging" }
num_enum = "0.1.1"
num_enum = "0.4"
parking_lot = "0.6"
process_execution = { path = "process_execution" }
rand = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/logging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ chrono = "0.4.10"
futures01 = { package = "futures", version = "0.1" }
lazy_static = "1"
log = "0.4"
num_enum = "0.1.1"
num_enum = "0.4"
parking_lot = "0.6"
simplelog = "0.7.4"
ui = { path = "../ui" }
Expand Down
73 changes: 41 additions & 32 deletions src/rust/engine/logging/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ impl Logger {
}

pub fn set_stderr_logger(&self, python_level: u64) -> Result<(), String> {
python_level.try_into().map(|level: PythonLogLevel| {
self.maybe_increase_global_verbosity(level.into());
*self.stderr_log.lock() = MaybeWriteLogger::new(
stderr(),
level.into(),
self.show_rust_3rdparty_logs.load(Ordering::SeqCst),
)
})
python_level
.try_into()
.map_err(|err| format!("{}", err))
.map(|level: PythonLogLevel| {
self.maybe_increase_global_verbosity(level.into());
*self.stderr_log.lock() = MaybeWriteLogger::new(
stderr(),
level.into(),
self.show_rust_3rdparty_logs.load(Ordering::SeqCst),
)
})
}

///
Expand All @@ -85,27 +88,30 @@ impl Logger {
python_level: u64,
) -> Result<std::os::unix::io::RawFd, String> {
use std::os::unix::io::AsRawFd;
python_level.try_into().and_then(|level: PythonLogLevel| {
{
// Maybe close open file by dropping the existing logger
*self.pantsd_log.lock() = MaybeWriteLogger::empty();
}
OpenOptions::new()
.create(true)
.append(true)
.open(log_file_path)
.map(|file| {
let fd = file.as_raw_fd();
self.maybe_increase_global_verbosity(level.into());
*self.pantsd_log.lock() = MaybeWriteLogger::new(
file,
level.into(),
self.show_rust_3rdparty_logs.load(Ordering::SeqCst),
);
fd
})
.map_err(|err| format!("Error opening pantsd logfile: {}", err))
})
python_level
.try_into()
.map_err(|err| format!("{}", err))
.and_then(|level: PythonLogLevel| {
{
// Maybe close open file by dropping the existing logger
*self.pantsd_log.lock() = MaybeWriteLogger::empty();
}
OpenOptions::new()
.create(true)
.append(true)
.open(log_file_path)
.map(|file| {
let fd = file.as_raw_fd();
self.maybe_increase_global_verbosity(level.into());
*self.pantsd_log.lock() = MaybeWriteLogger::new(
file,
level.into(),
self.show_rust_3rdparty_logs.load(Ordering::SeqCst),
);
fd
})
.map_err(|err| format!("Error opening pantsd logfile: {}", err))
})
}

pub fn log_from_python(
Expand All @@ -114,9 +120,12 @@ impl Logger {
python_level: u64,
target: &str,
) -> Result<(), String> {
python_level.try_into().map(|level: PythonLogLevel| {
log!(target: target, level.into(), "{}", message);
})
python_level
.try_into()
.map_err(|err| format!("{}", err))
.map(|level: PythonLogLevel| {
log!(target: target, level.into(), "{}", message);
})
}

pub fn register_engine_display(&self, engine_display: Arc<Mutex<EngineDisplay>>) -> Uuid {
Expand Down

0 comments on commit 59aa008

Please sign in to comment.