updated logging

This commit is contained in:
someone 2024-04-15 14:27:38 +02:00
parent 33723601b7
commit ec63deb6eb
3 changed files with 112 additions and 12 deletions

97
Cargo.lock generated
View file

@ -82,7 +82,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.58",
]
[[package]]
@ -259,6 +259,12 @@ dependencies = [
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "fnv"
version = "1.0.7"
@ -332,6 +338,12 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "hermit-abi"
version = "0.3.9"
@ -425,6 +437,17 @@ dependencies = [
"tokio",
]
[[package]]
name = "indexmap"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown",
"serde",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -596,7 +619,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.58",
]
[[package]]
@ -611,6 +634,30 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.79"
@ -717,7 +764,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.58",
]
[[package]]
@ -761,6 +808,7 @@ dependencies = [
"env_logger",
"log",
"tokio",
"utoipa",
]
[[package]]
@ -812,6 +860,16 @@ dependencies = [
"sled",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.58"
@ -862,7 +920,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.58",
]
[[package]]
@ -925,6 +983,37 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "utoipa"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "272ebdfbc99111033031d2f10e018836056e4d2c8e2acda76450ec7974269fa7"
dependencies = [
"indexmap",
"serde",
"serde_json",
"utoipa-gen",
]
[[package]]
name = "utoipa-gen"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3c9f4d08338c1bfa70dde39412a040a884c6f318b3d09aaaf3437a1e52027fc"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"regex",
"syn 2.0.58",
]
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"

View file

@ -15,4 +15,3 @@ env_logger = { workspace = true }
tokio = { workspace = true, features=["full"] }
axum = { workspace = true }
utoipa = { version = "4", features = ["axum_extras"] }
log = "0.4.21"

View file

@ -1,5 +1,4 @@
use axum::{extract::Request, routing::{get, post}, Router};
use log;
use std::env;
@ -8,11 +7,12 @@ async fn main() {
env::set_var("RUST_LOG", "trace");
env_logger::init();
// build our application with a route
// build our application with routes
let app = Router::new()
.route("/", get(root))
.route("/v1/secret/data/foo", post(foo));
.route("/v1/secret/data/foo", post(foo))
.route_service("/v1/secret/data/bar", post(bar))
.fallback(fallback);
// run our app with hyper, listening globally on port 8200
@ -20,12 +20,24 @@ async fn main() {
axum::serve(listener, app).await.unwrap();
}
/// Test function foo for routing
async fn foo(req: Request) -> String {
log::debug!("`{:?}`", req);
return String::from("RoutingTest successful");
String::from("RoutingTest foo successful")
}
/// Test function bar for routing
async fn bar(req: Request)-> String {
log::debug!("`{:?}`", req);
String::from("RoutingTest bar successful")
}
async fn fallback(req: Request)-> String {
log::debug!("`{:?}`", req);
String::from("Fallback triggered")
}
// basic handler that responds with a static string
async fn root() -> &'static str {
log::info!("Hello world");