依赖: Cargo.toml
[dependencies]
actix-web = "4"
log = "0.4.17"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.11", features = ["json", "valuable"] }
使用:
use actix_web::{App, HttpServer, Responder, get};
use tracing::info;
use tracing::{Level};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
tracing_subscriber::fmt().with_max_level(Level::INFO).json().init();
info!("start at http://127.0.0.1:80/");
HttpServer::new(|| {
App::new().service(index)
}).bind(("0.0.0.0", 80))?.run().await
}
#[get("/")]
async fn index() -> impl Responder {
let sid = "123123";
let did = "1231234444";
let t = 123;
info!(sid, did, "this is a message {}", t);
"hello, web actix".to_string()
}
输出到stdout
网友评论