Skip to content

Commit

Permalink
Run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Qqwy committed Dec 16, 2024
1 parent 85a48cf commit e23b035
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,40 +516,39 @@ impl Log for Logger {

if self.enabled_inner(record.metadata(), &cache) {
Python::with_gil(|py| {
// If an exception were triggered before this attempt to log,
// If an exception were triggered before this attempt to log,
// store it to the side for now and restore it afterwards.
let maybe_existing_exception = PyErr::take(py);
match self.log_inner(py, record, &cache) {

Ok(Some(logger)) => {
let filter = match self.caching {
Caching::Nothing => unreachable!(),
Caching::Loggers => LevelFilter::max(),
Caching::LoggersAndLevels => extract_max_level(logger.bind(py))
.unwrap_or_else(|e| {
// See detailed NOTE below
e.restore(py);
LevelFilter::max()
}),
};

let entry = CacheEntry { filter, logger };
self.store_to_cache(py, record.target(), entry);
}
Ok(None) => (),
Err(e) => {
// NOTE: If an exception was triggered _during_ logging, restore it as current Python exception.
// We have to use PyErr::restore because we cannot return a PyResult from the Log trait's log method.
Ok(Some(logger)) => {
let filter = match self.caching {
Caching::Nothing => unreachable!(),
Caching::Loggers => LevelFilter::max(),
Caching::LoggersAndLevels => extract_max_level(logger.bind(py))
.unwrap_or_else(|e| {
// See detailed NOTE below
e.restore(py);
LevelFilter::max()
}),
};

let entry = CacheEntry { filter, logger };
self.store_to_cache(py, record.target(), entry);
}
Ok(None) => (),
Err(e) => {
// NOTE: If an exception was triggered _during_ logging, restore it as current Python exception.
// We have to use PyErr::restore because we cannot return a PyResult from the Log trait's log method.
e.restore(py);
}
};

// If there was a prior exception, restore it now
// This ensures that the earliest thrown exception will be the one that's visible to the caller.
if let Some(e) = maybe_existing_exception {
e.restore(py);
},
};

// If there was a prior exception, restore it now
// This ensures that the earliest thrown exception will be the one that's visible to the caller.
if let Some(e) = maybe_existing_exception {
e.restore(py);
}
})
}
})
}
}

Expand Down

0 comments on commit e23b035

Please sign in to comment.