Skip to content

Commit 5dd9dc2

Browse files
committed
Merge remote-tracking branch 'upstream/main' into main
2 parents 0341865 + 9f3cde6 commit 5dd9dc2

28 files changed

+77
-89
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
2727
default = ["h1-server"]
2828
cookies = ["http-types/cookies"]
2929
h1-server = ["async-h1"]
30-
logger = ["femme"]
30+
logger = []
3131
docs = ["unstable"]
3232
sessions = ["async-session", "cookies"]
3333
sse = ["async-sse"]
@@ -39,7 +39,6 @@ async-session = { version = "3.0", optional = true }
3939
async-sse = { version = "5.1.0", optional = true }
4040
async-std = { version = "1.6.5", features = ["unstable"] }
4141
async-trait = "0.1.41"
42-
femme = { version = "2.1.1", optional = true }
4342
futures-util = "0.3.6"
4443
http-client = { version = "6.1.0", default-features = false }
4544
http-types = { version = "2.11.0", default-features = false, features = ["fs"] }
@@ -54,7 +53,9 @@ regex = "1.5.5"
5453
[dev-dependencies]
5554
async-std = { version = "1.6.5", features = ["unstable", "attributes"] }
5655
criterion = "0.3.3"
56+
femme = "2.1.1"
5757
juniper = "0.14.2"
58+
kv-log-macro = "1.0.7"
5859
lazy_static = "1.4.0"
5960
logtest = "2.0.0"
6061
portpicker = "0.1.0"

examples/catflap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[async_std::main]
33
async fn main() -> Result<(), std::io::Error> {
44
use std::{env, net::TcpListener, os::unix::io::FromRawFd};
5-
tide::log::start();
5+
femme::start();
66
let mut app = tide::new();
77
app.with(tide::log::LogMiddleware::new());
88
app.at("/").get(|_| async { Ok(CHANGE_THIS_TEXT) });

examples/chunked.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use tide::Body;
22

33
#[async_std::main]
44
async fn main() -> Result<(), std::io::Error> {
5-
tide::log::start();
5+
femme::start();
66
let mut app = tide::new();
77
app.with(tide::log::LogMiddleware::new());
88
app.at("/").get(|_| async {

examples/concurrent_listeners.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use tide::Request;
22

33
#[async_std::main]
44
async fn main() -> Result<(), std::io::Error> {
5-
tide::log::start();
5+
femme::start();
66
let mut app = tide::new();
77
app.with(tide::log::LogMiddleware::new());
88

examples/cookies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn remove_cookie(_req: Request) -> tide::Result {
2121

2222
#[async_std::main]
2323
async fn main() -> Result<(), std::io::Error> {
24-
tide::log::start();
24+
femme::start();
2525
let mut app = tide::new();
2626
app.with(tide::log::LogMiddleware::new());
2727

examples/error_handling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tide::{Body, Request, Response, Result, StatusCode};
55

66
#[async_std::main]
77
async fn main() -> Result<()> {
8-
tide::log::start();
8+
femme::start();
99
let mut app = tide::new();
1010
app.with(tide::log::LogMiddleware::new());
1111

examples/hello.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[async_std::main]
22
async fn main() -> Result<(), std::io::Error> {
3-
tide::log::start();
3+
femme::start();
44

55
let mut app = tide::new();
66
app.with(tide::log::LogMiddleware::new());

examples/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct Cat {
99

1010
#[async_std::main]
1111
async fn main() -> tide::Result<()> {
12-
tide::log::start();
12+
femme::start();
1313
let mut app = tide::new();
1414
app.with(tide::log::LogMiddleware::new());
1515

examples/middleware.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::sync::atomic::{AtomicUsize, Ordering};
22
use std::sync::Arc;
33

4+
use kv_log_macro::trace;
45
use tide::http::mime;
56
use tide::utils::{After, Before};
67
use tide::{Middleware, Next, Request, Response, Result, StatusCode};
@@ -25,7 +26,7 @@ impl UserDatabase {
2526
// it would likely be closely tied to a specific application
2627
async fn user_loader(mut request: Request, next: Next) -> Result {
2728
if let Some(user) = request.state::<UserDatabase>().find_user().await {
28-
tide::log::trace!("user loaded", {user: user.name});
29+
trace!("user loaded", {user: user.name});
2930
request.set_ext(user);
3031
Ok(next.run(request).await)
3132
// this middleware only needs to run before the endpoint, so
@@ -57,7 +58,7 @@ struct RequestCount(usize);
5758
impl Middleware for RequestCounterMiddleware {
5859
async fn handle(&self, mut req: Request, next: Next) -> Result {
5960
let count = self.requests_counted.fetch_add(1, Ordering::Relaxed);
60-
tide::log::trace!("request counter", { count: count });
61+
trace!("request counter", { count: count });
6162
req.set_ext(RequestCount(count));
6263

6364
let mut res = next.run(req).await;
@@ -84,7 +85,7 @@ const INTERNAL_SERVER_ERROR_HTML_PAGE: &str = "<html><body>
8485

8586
#[async_std::main]
8687
async fn main() -> Result<()> {
87-
tide::log::start();
88+
femme::start();
8889
let mut app = tide::with_state(UserDatabase::default());
8990

9091
app.with(After(|response: Response| async move {

examples/nested.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[async_std::main]
22
async fn main() -> Result<(), std::io::Error> {
3-
tide::log::start();
3+
femme::start();
44
let mut app = tide::new();
55
app.with(tide::log::LogMiddleware::new());
66
app.at("/").get(|_| async { Ok("Root") });

examples/redirect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use tide::{Redirect, Response, StatusCode};
22

33
#[async_std::main]
44
async fn main() -> Result<(), std::io::Error> {
5-
tide::log::start();
5+
femme::start();
66
let mut app = tide::new();
77
app.with(tide::log::LogMiddleware::new());
88
app.at("/").get(|_| async { Ok("Root") });

examples/sessions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[async_std::main]
22
async fn main() -> Result<(), std::io::Error> {
3-
tide::log::start();
3+
femme::start();
44
let mut app = tide::new();
55
app.with(tide::log::LogMiddleware::new());
66

examples/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl State {
1616

1717
#[async_std::main]
1818
async fn main() -> tide::Result<()> {
19-
tide::log::start();
19+
femme::start();
2020
let mut app = tide::with_state(State::new());
2121
app.with(tide::log::LogMiddleware::new());
2222
app.at("/").get(|req: tide::Request| async move {

examples/static_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[async_std::main]
22
async fn main() -> Result<(), std::io::Error> {
3-
tide::log::start();
3+
femme::start();
44
let mut app = tide::new();
55
app.with(tide::log::LogMiddleware::new());
66
app.at("/").get(|_| async { Ok("visit /src/*") });

examples/upload.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::Path;
33
use std::sync::Arc;
44

55
use async_std::{fs::OpenOptions, io};
6+
use kv_log_macro::info;
67
use tempfile::TempDir;
78
use tide::prelude::*;
89
use tide::{Body, Request, Response, StatusCode};
@@ -26,7 +27,7 @@ impl TempDirState {
2627

2728
#[async_std::main]
2829
async fn main() -> Result<(), IoError> {
29-
tide::log::start();
30+
femme::start();
3031
let mut app = tide::with_state(TempDirState::try_new()?);
3132
app.with(tide::log::LogMiddleware::new());
3233

@@ -49,7 +50,7 @@ async fn main() -> Result<(), IoError> {
4950

5051
let bytes_written = io::copy(req, file).await?;
5152

52-
tide::log::info!("file written", {
53+
info!("file written", {
5354
bytes: bytes_written,
5455
path: fs_path.canonicalize()?.to_str()
5556
});

src/fs/serve_dir.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::log;
21
use crate::{Body, Endpoint, Request, Response, Result, StatusCode};
32

43
use async_std::path::PathBuf as AsyncPathBuf;
4+
use kv_log_macro::{info, warn};
55

66
use std::path::{Path, PathBuf};
77
use std::{ffi::OsStr, io};
@@ -37,17 +37,17 @@ impl Endpoint for ServeDir {
3737
}
3838
}
3939

40-
log::info!("Requested file: {:?}", file_path);
40+
info!("Requested file: {:?}", file_path);
4141

4242
let file_path = AsyncPathBuf::from(file_path);
4343
if !file_path.starts_with(&self.dir) {
44-
log::warn!("Unauthorized attempt to read: {:?}", file_path);
44+
warn!("Unauthorized attempt to read: {:?}", file_path);
4545
Ok(Response::new(StatusCode::Forbidden))
4646
} else {
4747
match Body::from_file(&file_path).await {
4848
Ok(body) => Ok(Response::builder(StatusCode::Ok).body(body).build()),
4949
Err(e) if e.kind() == io::ErrorKind::NotFound => {
50-
log::warn!("File not found: {:?}", &file_path);
50+
warn!("File not found: {:?}", &file_path);
5151
Ok(Response::new(StatusCode::NotFound))
5252
}
5353
Err(e) => Err(e.into()),

src/fs/serve_file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::log;
21
use crate::{Body, Endpoint, Request, Response, Result, StatusCode};
32
use std::io;
43
use std::path::Path;
54

65
use async_std::path::PathBuf as AsyncPathBuf;
76
use async_trait::async_trait;
7+
use kv_log_macro::warn;
88

99
pub(crate) struct ServeFile {
1010
path: AsyncPathBuf,
@@ -26,7 +26,7 @@ impl Endpoint for ServeFile {
2626
match Body::from_file(&self.path).await {
2727
Ok(body) => Ok(Response::builder(StatusCode::Ok).body(body).build()),
2828
Err(e) if e.kind() == io::ErrorKind::NotFound => {
29-
log::warn!("File not found: {:?}", &self.path);
29+
warn!("File not found: {:?}", &self.path);
3030
Ok(Response::new(StatusCode::NotFound))
3131
}
3232
Err(e) => Err(e.into()),

src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
//!
3333
//! #[async_std::main]
3434
//! async fn main() -> tide::Result<()> {
35-
//! tide::log::start();
3635
//! let mut app = tide::new();
37-
//! app.with(tide::log::LogMiddleware::new());
3836
//! app.at("/orders/shoes").post(order_shoes);
3937
//! app.listen("127.0.0.1:8080").await?;
4038
//! Ok(())

src/listener/concurrent_listener.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use futures_util::stream::{futures_unordered::FuturesUnordered, StreamExt};
1313
/// ```rust
1414
/// fn main() -> Result<(), std::io::Error> {
1515
/// async_std::task::block_on(async {
16-
/// tide::log::start();
1716
/// let mut app = tide::new();
1817
/// app.at("/").get(|_| async { Ok("Hello, world!") });
1918
///

src/listener/failover_listener.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::Server;
44
use std::fmt::{self, Debug, Display, Formatter};
55

66
use async_std::io;
7+
use kv_log_macro::info;
78

89
use crate::listener::ListenInfo;
910

@@ -15,7 +16,6 @@ use crate::listener::ListenInfo;
1516
/// ```rust
1617
/// fn main() -> Result<(), std::io::Error> {
1718
/// async_std::task::block_on(async {
18-
/// tide::log::start();
1919
/// let mut app = tide::new();
2020
/// app.at("/").get(|_| async { Ok("Hello, world!") });
2121
///
@@ -103,7 +103,7 @@ impl Listener for FailoverListener {
103103
return Ok(());
104104
}
105105
Err(e) => {
106-
crate::log::info!("unable to bind", {
106+
info!("unable to bind", {
107107
listener: listener.to_string(),
108108
error: e.to_string()
109109
});

src/listener/tcp_listener.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use super::{is_transient_error, ListenInfo};
22

33
use crate::listener::Listener;
4-
use crate::{log, Server};
4+
use crate::Server;
55

66
use std::fmt::{self, Display, Formatter};
77

88
use async_std::net::{self, SocketAddr, TcpStream};
99
use async_std::prelude::*;
1010
use async_std::{io, task};
11+
use kv_log_macro::error;
1112

1213
/// This represents a tide [Listener](crate::listener::Listener) that
1314
/// wraps an [async_std::net::TcpListener]. It is implemented as an
@@ -56,7 +57,7 @@ fn handle_tcp(app: Server, stream: TcpStream) {
5657
});
5758

5859
if let Err(error) = fut.await {
59-
log::error!("async-h1 error", { error: error.to_string() });
60+
error!("async-h1 error", { error: error.to_string() });
6061
}
6162
});
6263
}
@@ -102,7 +103,7 @@ impl Listener for TcpListener {
102103
Err(ref e) if is_transient_error(e) => continue,
103104
Err(error) => {
104105
let delay = std::time::Duration::from_millis(500);
105-
crate::log::error!("Error: {}. Pausing for {:?}.", error, delay);
106+
error!("Error: {}. Pausing for {:?}.", error, delay);
106107
task::sleep(delay).await;
107108
continue;
108109
}

src/listener/unix_listener.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use super::{is_transient_error, ListenInfo};
22

33
use crate::listener::Listener;
4-
use crate::{log, Server};
4+
use crate::Server;
55

66
use std::fmt::{self, Display, Formatter};
77

88
use async_std::os::unix::net::{self, SocketAddr, UnixStream};
99
use async_std::path::PathBuf;
1010
use async_std::prelude::*;
1111
use async_std::{io, task};
12+
use kv_log_macro::error;
1213

1314
/// This represents a tide [Listener](crate::listener::Listener) that
1415
/// wraps an [async_std::os::unix::net::UnixListener]. It is implemented as an
@@ -57,7 +58,7 @@ fn handle_unix(app: Server, stream: UnixStream) {
5758
});
5859

5960
if let Err(error) = fut.await {
60-
log::error!("async-h1 error", { error: error.to_string() });
61+
error!("async-h1 error", { error: error.to_string() });
6162
}
6263
});
6364
}
@@ -100,7 +101,7 @@ impl Listener for UnixListener {
100101
Err(ref e) if is_transient_error(e) => continue,
101102
Err(error) => {
102103
let delay = std::time::Duration::from_millis(500);
103-
crate::log::error!("Error: {}. Pausing for {:?}.", error, delay);
104+
error!("Error: {}. Pausing for {:?}.", error, delay);
104105
task::sleep(delay).await;
105106
continue;
106107
}

0 commit comments

Comments
 (0)