remove custom log tools in favor of macro crate

Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
staging
Yoshua Wuyts 5 years ago
parent be123b2ec5
commit 9c82d5e3f3
No known key found for this signature in database
GPG Key ID: 24EA8164F96777ED

@ -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;

@ -4,8 +4,8 @@ use std::thread;
use crossbeam_channel::{unbounded, Sender};
use lazy_static::lazy_static;
use kv_log_macro::trace;
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…
Cancel
Save