Skip to content

Commit 33c6ce0

Browse files
authored
Merge branch 'main' into patch-state-request
2 parents b8ba6c9 + e79e4f6 commit 33c6ce0

30 files changed

+88
-98
lines changed

.github/workflows/ci.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
uses: actions-rs/cargo@v1
3232
with:
3333
command: check
34-
args: --all --bins --examples
34+
args: --all --bins --examples --features logger
3535

3636
- name: check avoid-dev-deps
3737
uses: actions-rs/cargo@v1
@@ -44,7 +44,7 @@ jobs:
4444
uses: actions-rs/cargo@v1
4545
with:
4646
command: check
47-
args: --all --bins --examples --tests --features unstable
47+
args: --all --bins --examples --tests --features unstable,logger
4848

4949
- name: check no-default-features
5050
uses: actions-rs/cargo@v1
@@ -62,13 +62,13 @@ jobs:
6262
uses: actions-rs/cargo@v1
6363
with:
6464
command: test
65-
args: --all
65+
args: --all --features logger
6666

6767
- name: tests unstable
6868
uses: actions-rs/cargo@v1
6969
with:
7070
command: test
71-
args: --all --features unstable
71+
args: --all --features unstable,logger
7272

7373
check_fmt_and_docs:
7474
name: Checking fmt, clippy, and docs
@@ -82,7 +82,7 @@ jobs:
8282
rustc --version
8383
8484
- name: clippy
85-
run: cargo clippy --tests --examples -- -D warnings
85+
run: cargo clippy --tests --examples --features logger -- -D warnings
8686

8787
- name: fmt
8888
run: cargo fmt --all -- --check

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"

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ team. Use at your own risk.</sup>
133133
### Auth
134134
* [tide-http-auth](https://github.com/chrisdickinson/tide-http-auth)
135135
* [tide-openidconnect](https://github.com/malyn/tide-openidconnect)
136-
* [tide-jwt](htps://github.com/nyxtom/tide-jwt)
136+
* [tide-jwt](https://github.com/nyxtom/tide-jwt)
137137

138138
### Testing
139139
* [tide-testing](https://github.com/jbr/tide-testing)
@@ -148,6 +148,7 @@ team. Use at your own risk.</sup>
148148
* [tide-compressed-sse](https://github.com/Yarn/tide_compressed_sse)
149149
* [tide-websockets](https://github.com/http-rs/tide-websockets)
150150
* [tide-csrf](https://github.com/malyn/tide-csrf)
151+
* [tide-flash](https://github.com/nyxtom/tide-flash)
151152

152153
### Session Stores
153154
* [async-redis-session](https://github.com/jbr/async-redis-session)

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
}

0 commit comments

Comments
 (0)