mirror of
https://gitee.com/openharmony/third_party_rust_log
synced 2024-12-03 13:31:50 +00:00
Merge pull request #213 from sfackler/no-panic-handler
Remove deprecated panic hook
This commit is contained in:
commit
ac921f9279
@ -34,7 +34,6 @@ release_max_level_info = []
|
||||
release_max_level_debug = []
|
||||
release_max_level_trace = []
|
||||
|
||||
nightly = []
|
||||
use_std = []
|
||||
default = ["use_std"]
|
||||
|
||||
|
43
src/lib.rs
43
src/lib.rs
@ -249,7 +249,6 @@
|
||||
html_root_url = "https://docs.rs/log/0.3.8")]
|
||||
#![warn(missing_docs)]
|
||||
#![deny(missing_debug_implementations)]
|
||||
#![cfg_attr(feature = "nightly", feature(panic_handler))]
|
||||
|
||||
#![cfg_attr(not(feature = "use_std"), no_std)]
|
||||
|
||||
@ -1202,48 +1201,6 @@ impl error::Error for ParseLevelError {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Deprecated
|
||||
///
|
||||
/// Use https://crates.io/crates/log-panics instead.
|
||||
#[cfg(all(feature = "nightly", feature = "use_std"))]
|
||||
pub fn log_panics() {
|
||||
std::panic::set_hook(Box::new(panic::log));
|
||||
}
|
||||
|
||||
// inner module so that the reporting module is log::panic instead of log
|
||||
#[cfg(all(feature = "nightly", feature = "use_std"))]
|
||||
mod panic {
|
||||
use std::panic::PanicInfo;
|
||||
use std::thread;
|
||||
|
||||
pub fn log(info: &PanicInfo) {
|
||||
let thread = thread::current();
|
||||
let thread = thread.name().unwrap_or("<unnamed>");
|
||||
|
||||
let msg = match info.payload().downcast_ref::<&'static str>() {
|
||||
Some(s) => *s,
|
||||
None => {
|
||||
match info.payload().downcast_ref::<String>() {
|
||||
Some(s) => &s[..],
|
||||
None => "Box<Any>",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match info.location() {
|
||||
Some(location) => {
|
||||
error!("thread '{}' panicked at '{}': {}:{}",
|
||||
thread,
|
||||
msg,
|
||||
location.file(),
|
||||
location.line())
|
||||
}
|
||||
None => error!("thread '{}' panicked at '{}'", thread, msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn logger() -> Option<&'static Log> {
|
||||
if STATE.load(Ordering::SeqCst) != INITIALIZED {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user