diff --git a/Cargo.toml b/Cargo.toml index 3c3eaa8e..87d3930b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "tokio-trace", + "tokio-trace-futures", "tokio-trace-tower", "tokio-trace-tower-http", "tokio-trace-log", diff --git a/tokio-trace-env-logger/Cargo.toml b/tokio-trace-env-logger/Cargo.toml index d3b889e7..06654315 100644 --- a/tokio-trace-env-logger/Cargo.toml +++ b/tokio-trace-env-logger/Cargo.toml @@ -10,6 +10,7 @@ log = "0.4" [dev-dependencies] tokio-trace = { path = "../tokio-trace" } +tokio-trace-futures = { path = "../tokio-trace-futures" } hyper = "0.12" futures = "0.1" ansi_term = "0.11" diff --git a/tokio-trace-env-logger/examples/hyper-echo.rs b/tokio-trace-env-logger/examples/hyper-echo.rs index 3ce1c065..26aa0032 100644 --- a/tokio-trace-env-logger/examples/hyper-echo.rs +++ b/tokio-trace-env-logger/examples/hyper-echo.rs @@ -2,6 +2,7 @@ extern crate futures; extern crate hyper; #[macro_use] extern crate tokio_trace; +extern crate tokio_trace_futures; extern crate tokio_trace_env_logger; extern crate tokio; @@ -17,10 +18,8 @@ use std::str; mod sloggish; use self::sloggish::SloggishSubscriber; -use tokio_trace::{ - Level, - instrument::{Instrument, Instrumented}, -}; +use tokio_trace::Level; +use tokio_trace_futures::{Instrument, Instrumented}; type BoxFut = Box, Error = hyper::Error> + Send>; diff --git a/tokio-trace-futures/Cargo.toml b/tokio-trace-futures/Cargo.toml new file mode 100644 index 00000000..606a1bb9 --- /dev/null +++ b/tokio-trace-futures/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "tokio-trace-futures" +version = "0.0.1" +authors = ["Eliza Weisman "] + +[dependencies] +futures = "0.1" +tokio-trace = { path = "../tokio-trace" } + +[dev-dependencies] +tokio-trace = { path = "../tokio-trace", features = ["test-support"] } diff --git a/tokio-trace/src/instrument.rs b/tokio-trace-futures/src/lib.rs similarity index 95% rename from tokio-trace/src/instrument.rs rename to tokio-trace-futures/src/lib.rs index 57f04872..fbb7302f 100644 --- a/tokio-trace/src/instrument.rs +++ b/tokio-trace-futures/src/lib.rs @@ -1,4 +1,8 @@ -use super::Span; +#[cfg_attr(test, macro_use)] +extern crate tokio_trace; +extern crate futures; + +use tokio_trace::Span; use futures::{Async, Future, Sink, Stream, Poll, StartSend}; // TODO: seal? @@ -92,7 +96,7 @@ impl Sink for Instrumented { #[cfg(test)] mod tests { use futures::{prelude::*, task, future, stream}; - use ::{span, subscriber}; + use tokio_trace::{span, subscriber}; use super::*; #[test] @@ -131,7 +135,7 @@ mod tests { ) .run(); MyFuture { polls: 0 } - .instrument(span!("foo",)) + .instrument(span!("foo")) .wait().unwrap(); } @@ -166,7 +170,7 @@ mod tests { .with_state(span::State::Idle) ) .run(); - let foo = span!("foo",); + let foo = span!("foo"); MyFuture { polls: 0 } .instrument(foo.clone()) .wait().unwrap(); @@ -204,7 +208,7 @@ mod tests { ) .run(); MyFuture { polls: 0 } - .instrument(span!("foo",)) + .instrument(span!("foo")) .wait().unwrap_err(); } @@ -233,7 +237,7 @@ mod tests { ) .run(); stream::iter_ok::<_, ()>(&[1, 2, 3]) - .instrument(span!("foo",)) + .instrument(span!("foo")) .for_each(|_| { future::ok(()) }) .wait().unwrap(); } diff --git a/tokio-trace-log/Cargo.toml b/tokio-trace-log/Cargo.toml index 17fbb49f..e332113b 100644 --- a/tokio-trace-log/Cargo.toml +++ b/tokio-trace-log/Cargo.toml @@ -6,6 +6,3 @@ authors = ["Eliza Weisman "] [dependencies] tokio-trace = { path = "../tokio-trace" } log = "0.4" - -[dev-dependencies] -env_logger = "0.5" diff --git a/tokio-trace-tower-http/Cargo.toml b/tokio-trace-tower-http/Cargo.toml index 141506dc..59504336 100644 --- a/tokio-trace-tower-http/Cargo.toml +++ b/tokio-trace-tower-http/Cargo.toml @@ -5,11 +5,11 @@ authors = ["Eliza Weisman "] [dependencies] tokio-trace = { path = "../tokio-trace" } +tokio-trace-futures = { path = "../tokio-trace-futures" } futures = "0.1" tower-service = { git = "https://github.com/tower-rs/tower.git" } http = "0.1" - [dev-dependencies] bytes = "0.4" h2 = "0.1.11" diff --git a/tokio-trace-tower-http/examples/tower-h2-server.rs b/tokio-trace-tower-http/examples/tower-h2-server.rs index cfd96193..203287bf 100644 --- a/tokio-trace-tower-http/examples/tower-h2-server.rs +++ b/tokio-trace-tower-http/examples/tower-h2-server.rs @@ -5,6 +5,7 @@ extern crate http; extern crate tokio; #[macro_use] extern crate tokio_trace; +extern crate tokio_trace_futures; extern crate tokio_trace_tower_http; extern crate tower_h2; extern crate tower_service; @@ -16,10 +17,8 @@ use tokio::net::TcpListener; use tokio::runtime::Runtime; use tower_h2::{Body, Server, RecvBody}; use tower_service::{NewService, Service}; -use tokio_trace::{ - Level, - instrument::Instrument, -}; +use tokio_trace::Level; +use tokio_trace_futures::Instrument; #[path = "../../tokio-trace/examples/sloggish/sloggish_subscriber.rs"] mod sloggish; diff --git a/tokio-trace-tower-http/src/lib.rs b/tokio-trace-tower-http/src/lib.rs index c40ee6be..efb7f804 100644 --- a/tokio-trace-tower-http/src/lib.rs +++ b/tokio-trace-tower-http/src/lib.rs @@ -2,10 +2,11 @@ extern crate tower_service; extern crate http; #[macro_use] extern crate tokio_trace; +extern crate tokio_trace_futures; extern crate futures; use futures::{Future, Poll}; -use tokio_trace::instrument::{Instrumented, Instrument}; +use tokio_trace_futures::{Instrumented, Instrument}; use tower_service::{Service, NewService}; #[derive(Clone, Debug)] diff --git a/tokio-trace-tower/Cargo.toml b/tokio-trace-tower/Cargo.toml index fcbe8c02..44810fb0 100644 --- a/tokio-trace-tower/Cargo.toml +++ b/tokio-trace-tower/Cargo.toml @@ -5,5 +5,6 @@ authors = ["Eliza Weisman "] [dependencies] tokio-trace = { path = "../tokio-trace" } +tokio-trace-futures = { path = "../tokio-trace-futures" } futures = "0.1" tower-service = { git = "https://github.com/tower-rs/tower.git" } diff --git a/tokio-trace-tower/src/lib.rs b/tokio-trace-tower/src/lib.rs index f6455a76..b6438cac 100644 --- a/tokio-trace-tower/src/lib.rs +++ b/tokio-trace-tower/src/lib.rs @@ -1,9 +1,10 @@ extern crate tower_service; #[macro_use] extern crate tokio_trace; +extern crate tokio_trace_futures; extern crate futures; -use tokio_trace::instrument::{Instrumented, Instrument}; +use tokio_trace_futures::{Instrumented, Instrument}; use tower_service::Service; use std::fmt; diff --git a/tokio-trace/Cargo.toml b/tokio-trace/Cargo.toml index e0712829..5e21fdcf 100644 --- a/tokio-trace/Cargo.toml +++ b/tokio-trace/Cargo.toml @@ -3,6 +3,10 @@ name = "tokio-trace" version = "0.1.0" authors = ["Eliza Weisman "] +[features] +default = [] +test-support = [] + [dependencies] futures = "0.1" diff --git a/tokio-trace/src/lib.rs b/tokio-trace/src/lib.rs index 1640e807..c3dfa828 100644 --- a/tokio-trace/src/lib.rs +++ b/tokio-trace/src/lib.rs @@ -117,31 +117,6 @@ use std::{fmt, slice, time::Instant}; use self::dedup::IteratorDedup; -#[repr(usize)] -#[derive(Copy, Eq, Debug, Hash)] -pub enum Level { - /// The "error" level. - /// - /// Designates very serious errors. - Error = 1, // This way these line up with the discriminants for LevelFilter below - /// The "warn" level. - /// - /// Designates hazardous situations. - Warn, - /// The "info" level. - /// - /// Designates useful information. - Info, - /// The "debug" level. - /// - /// Designates lower priority information. - Debug, - /// The "trace" level. - /// - /// Designates very low priority, often extremely verbose, information. - Trace, -} - #[doc(hidden)] #[macro_export] macro_rules! static_meta { @@ -255,9 +230,33 @@ macro_rules! event { ($lvl:expr, { $($k:ident = $val:expr),* }, $($arg:tt)+ ) => (event!(target: None, $lvl, { $($k = $val),* }, $($arg)+)) } +#[repr(usize)] +#[derive(Copy, Eq, Debug, Hash)] +pub enum Level { + /// The "error" level. + /// + /// Designates very serious errors. + Error = 1, // This way these line up with the discriminants for LevelFilter below + /// The "warn" level. + /// + /// Designates hazardous situations. + Warn, + /// The "info" level. + /// + /// Designates useful information. + Info, + /// The "debug" level. + /// + /// Designates lower priority information. + Debug, + /// The "trace" level. + /// + /// Designates very low priority, often extremely verbose, information. + Trace, +} + mod dedup; mod dispatcher; -pub mod instrument; pub mod span; pub mod subscriber; diff --git a/tokio-trace/src/span.rs b/tokio-trace/src/span.rs index 8434b7cc..e459d75f 100644 --- a/tokio-trace/src/span.rs +++ b/tokio-trace/src/span.rs @@ -542,9 +542,10 @@ impl cmp::PartialEq for DataInner { } } -#[cfg(test)] +#[cfg(any(test, feature = "test-support"))] pub use self::test_support::*; -#[cfg(test)] + +#[cfg(any(test, feature = "test-support"))] mod test_support { use ::{ Value, span::State }; use std::collections::HashMap; diff --git a/tokio-trace/src/subscriber.rs b/tokio-trace/src/subscriber.rs index 69a52def..61d92f52 100644 --- a/tokio-trace/src/subscriber.rs +++ b/tokio-trace/src/subscriber.rs @@ -98,9 +98,10 @@ where } } -#[cfg(test)] +#[cfg(any(test, feature = "test-support"))] pub use self::test_support::*; -#[cfg(test)] + +#[cfg(any(test, feature = "test-support"))] mod test_support { use super::Subscriber; use ::{Event, SpanData, Meta};