配置日志级别 tracing-subscriber 通过EnvFilter过滤日志,低于配置级别的日志不会显示 usetracing_appender::{non_blocking::WorkerGuard,rolling};usetracing_subscriber::{fmt::{self,time::OffsetTime},layer::SubscriberExt,util::SubscriberInitExt,EnvFilter,Registry};usetime::{macros::format_description,UtcOffset...
asyncfnaaa(){}asyncfnafter(){}#[tokio::main]asyncfnmain(){tracing_subscriber::fmt().with_target(false).compact().init();lettrace_layer=TraceLayer::new_for_http().make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO)).on_request(trace::DefaultOnRequest::new().l...
您可以使用tracing-subscriber机箱快速启动和运行:
tracing 用于记录和追踪程序中的事件和日志,可以发出结构化的日志信息。通过结合 tracing_subscriber,可以控制日志级别和输出格式。tracing 及其生态系统为异步程序和复杂系统提供了强大的日志记录功能。 use axum::{extract::Form, response::Html, routing::get, Router}; use serde::Deserialize; use tracing_subscri...
tracing_subscriber::fmt::init(); tracing::info!("服务已启动");letfrentend_routers= frontend::router();letbackend_routers= backend::router();letapp= Router::new() .nest("/", frentend_routers) .nest("/admin", backend_routers);
tracing_subscriber::EnvFilter::try_from_default_env() .unwrap_or_else(|_|"debug".into()), ) .with(tracing_subscriber::fmt::layer()) .init();letpath= PathBuf::from("/tmp/axum/helloworld");let_= tokio::fs::remove_file(&path).await; ...
#[tokio::main]asyncfnmain(){// Set the RUST_LOG, if it hasn't been explicitly definedifstd::env::var_os("RUST_LOG").is_none(){std::env::set_var("RUST_LOG","example_sse=debug,tower_http=debug")}tracing_subscriber::fmt::init();// our routerletapp=Router::new().route("/upl...
tracing_subscriber::registry() .with(tracing_subscriber::EnvFilter::new( std::env::var("RUST_LOG").unwrap_or_else(|_| "example_tokio_postgres=debug".into()), )) .with(tracing_subscriber::fmt::layer()) .init(); let db_connection_str = std::env::var("DATABASE_URL") ...
tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() .unwrap_or_else(|_|"example_sse=debug,tower_http=debug".into()), ) .with(tracing_subscriber::fmt::layer()) .init();// build our applicationletapp=app();// run itletlistener= tokio::net::...
("RUST_LOG","example_static_file_server=debug,tower_http=debug",)}tracing_subscriber::fmt::init();letapp=Router::new().nest("/static",get_service(ServeDir::new(".")).handle_error(|error:std::io::Error|asyncmove{(StatusCode::INTERNAL_SERVER_ERROR,format!("Unhandled internal error: {...