mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
Merge #199
199: remove custom log code in favor of macro crate r=yoshuawuyts a=yoshuawuyts This removes our custom log macro code in favor of using [`kv-log-macro`](https://github.com/yoshuawuyts/kv-log-macro). This is a temporary crate that exists only until https://github.com/rust-lang-nursery/log/pull/353 lands which enables progress on https://github.com/rust-lang-nursery/log/issues/328. Thanks! Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
This commit is contained in:
commit
36c437bc09
5 changed files with 24 additions and 63 deletions
|
@ -38,6 +38,7 @@ mio-uds = "0.6.7"
|
|||
num_cpus = "1.10.1"
|
||||
pin-utils = "0.1.0-alpha.4"
|
||||
slab = "0.4.2"
|
||||
kv-log-macro = "1.0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
femme = "1.2.0"
|
||||
|
|
|
@ -6,13 +6,14 @@ use std::sync::Arc;
|
|||
use std::task::{RawWaker, RawWakerVTable};
|
||||
use std::thread::{self, Thread};
|
||||
|
||||
use super::log_utils;
|
||||
use super::pool;
|
||||
use super::task;
|
||||
use crate::future::Future;
|
||||
use crate::task::{Context, Poll, Waker};
|
||||
use crate::utils::abort_on_panic;
|
||||
|
||||
use kv_log_macro::trace;
|
||||
|
||||
/// Spawns a task and blocks the current thread on its result.
|
||||
///
|
||||
/// Calling this function is similar to [spawning] a thread and immediately [joining] it, except an
|
||||
|
@ -58,13 +59,11 @@ where
|
|||
// Log this `block_on` operation.
|
||||
let child_id = tag.task_id().as_u64();
|
||||
let parent_id = pool::get_task(|t| t.id().as_u64()).unwrap_or(0);
|
||||
log_utils::print(
|
||||
format_args!("block_on"),
|
||||
log_utils::LogData {
|
||||
parent_id,
|
||||
child_id,
|
||||
},
|
||||
);
|
||||
|
||||
trace!("block_on", {
|
||||
parent_id: parent_id,
|
||||
child_id: child_id,
|
||||
});
|
||||
|
||||
// Wrap the future into one that drops task-local variables on exit.
|
||||
let future = async move {
|
||||
|
@ -73,13 +72,11 @@ where
|
|||
// Abort on panic because thread-local variables behave the same way.
|
||||
abort_on_panic(|| pool::get_task(|task| task.metadata().local_map.clear()));
|
||||
|
||||
log_utils::print(
|
||||
format_args!("block_on completed"),
|
||||
log_utils::LogData {
|
||||
parent_id,
|
||||
child_id,
|
||||
},
|
||||
);
|
||||
trace!("block_on completed", {
|
||||
parent_id: parent_id,
|
||||
child_id: child_id,
|
||||
});
|
||||
|
||||
res
|
||||
};
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
use std::fmt::Arguments;
|
||||
|
||||
/// This struct only exists because kv logging isn't supported from the macros right now.
|
||||
pub(crate) struct LogData {
|
||||
pub parent_id: u64,
|
||||
pub child_id: u64,
|
||||
}
|
||||
|
||||
impl<'a> log::kv::Source for LogData {
|
||||
fn visit<'kvs>(
|
||||
&'kvs self,
|
||||
visitor: &mut dyn log::kv::Visitor<'kvs>,
|
||||
) -> Result<(), log::kv::Error> {
|
||||
visitor.visit_pair("parent_id".into(), self.parent_id.into())?;
|
||||
visitor.visit_pair("child_id".into(), self.child_id.into())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print(msg: Arguments<'_>, key_values: impl log::kv::Source) {
|
||||
log::logger().log(
|
||||
&log::Record::builder()
|
||||
.args(msg)
|
||||
.key_values(&key_values)
|
||||
.level(log::Level::Trace)
|
||||
.target(module_path!())
|
||||
.module_path(Some(module_path!()))
|
||||
.file(Some(file!()))
|
||||
.line(Some(line!()))
|
||||
.build(),
|
||||
);
|
||||
}
|
|
@ -32,7 +32,6 @@ pub use task::{JoinHandle, Task, TaskId};
|
|||
|
||||
mod block_on;
|
||||
mod local;
|
||||
mod log_utils;
|
||||
mod pool;
|
||||
mod sleep;
|
||||
mod task;
|
||||
|
|
|
@ -3,9 +3,9 @@ use std::ptr;
|
|||
use std::thread;
|
||||
|
||||
use crossbeam_channel::{unbounded, Sender};
|
||||
use kv_log_macro::trace;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use super::log_utils;
|
||||
use super::task;
|
||||
use super::{JoinHandle, Task};
|
||||
use crate::future::Future;
|
||||
|
@ -130,13 +130,11 @@ where
|
|||
// Log this `spawn` operation.
|
||||
let child_id = tag.task_id().as_u64();
|
||||
let parent_id = get_task(|t| t.id().as_u64()).unwrap_or(0);
|
||||
log_utils::print(
|
||||
format_args!("spawn"),
|
||||
log_utils::LogData {
|
||||
parent_id,
|
||||
child_id,
|
||||
},
|
||||
);
|
||||
|
||||
trace!("spawn", {
|
||||
parent_id: parent_id,
|
||||
child_id: child_id,
|
||||
});
|
||||
|
||||
// Wrap the future into one that drops task-local variables on exit.
|
||||
let future = async move {
|
||||
|
@ -145,13 +143,11 @@ where
|
|||
// Abort on panic because thread-local variables behave the same way.
|
||||
abort_on_panic(|| get_task(|task| task.metadata().local_map.clear()));
|
||||
|
||||
log_utils::print(
|
||||
format_args!("spawn completed"),
|
||||
log_utils::LogData {
|
||||
parent_id,
|
||||
child_id,
|
||||
},
|
||||
);
|
||||
trace!("spawn completed", {
|
||||
parent_id: parent_id,
|
||||
child_id: child_id,
|
||||
});
|
||||
|
||||
res
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue