mirror of
https://github.com/DefectingCat/phthonus
synced 2025-07-16 00:51:31 +00:00
init with tokio
This commit is contained in:
1204
web/Rust/axum/Cargo.lock
generated
1204
web/Rust/axum/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,27 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "axum"
|
name = "phthonus-axum"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
# server
|
||||||
|
axum = "0.7.5"
|
||||||
|
tokio = { version = "1.40.0", features = ["full"] }
|
||||||
|
tower = "0.5.1"
|
||||||
|
tower-http = { version = "0.5.2", features = ["full"] }
|
||||||
|
tracing = "0.1.40"
|
||||||
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
|
# error
|
||||||
|
anyhow = "1.0.88"
|
||||||
|
thiserror = "1.0.63"
|
||||||
|
# tools
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
serde = { version = "1.0.210", features = ["derive", "serde_derive"] }
|
||||||
|
serde_json = { version = "1.0.128" }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
panic = "abort" # Strip expensive panic clean-up logic
|
||||||
|
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
|
||||||
|
# opt-level = "s" # Optimize for binary size
|
||||||
|
strip = true # Remove debug symbols
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
fn main() {
|
use dotenvy::dotenv;
|
||||||
println!("Hello, world!");
|
use tracing::info;
|
||||||
|
use utils::init_logger;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
dotenv().ok();
|
||||||
|
init_logger();
|
||||||
|
info!("Hello, world!");
|
||||||
}
|
}
|
||||||
|
28
web/Rust/axum/src/utils/mod.rs
Normal file
28
web/Rust/axum/src/utils/mod.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
use tracing_subscriber::{fmt, prelude::*, registry, EnvFilter};
|
||||||
|
|
||||||
|
/// Initializes the logger for tracing.
|
||||||
|
///
|
||||||
|
/// This function sets up the necessary layers for tracing using the `tracing_subscriber`
|
||||||
|
/// crate. It configures the formatting layer and environment filter based on the value
|
||||||
|
/// of the `LIMOS_LOG` environment variable (defaulting to "info" if not set).
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use utils::init_logger;
|
||||||
|
///
|
||||||
|
/// fn test() {
|
||||||
|
/// init_logger();
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub fn init_logger() {
|
||||||
|
let formatting_layer = fmt::layer()
|
||||||
|
// .pretty()
|
||||||
|
.with_thread_ids(false)
|
||||||
|
.with_target(false)
|
||||||
|
.with_writer(std::io::stdout);
|
||||||
|
|
||||||
|
let env_layer = EnvFilter::try_from_env("axum").unwrap_or_else(|_| "info".into());
|
||||||
|
|
||||||
|
registry().with(env_layer).with(formatting_layer).init();
|
||||||
|
}
|
Reference in New Issue
Block a user