Logging

提供基本的 Log 功能的中间件.

配置 Cargo.toml

salvo = { version = "*", features = ["logging"] }

示例代码

use salvo::logging::Logger;
use salvo::prelude::*;

#[handler]
async fn hello() -> &'static str {
    "Hello World"
}

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt().init();

    let router = Router::new().hoop(Logger).get(hello);

    let acceptor = TcpListener::new("127.0.0.1:7878").bind().await;
    Server::new(acceptor).serve(router).await;
}
[package]
name = "example-logging"
version = "0.1.0"
edition = "2021"
publish = false


[dependencies]
salvo = { git = "https://github.com/salvo-rs/salvo.git", features = ["logging"] }
tokio = { version = "1", features = ["macros"] }
tracing = "0.1"
tracing-subscriber = "0.3"