Skip to content

Commit

Permalink
console_subscriber and tracing_subscriber now togglable by features
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodyTheCat committed Oct 5, 2024
1 parent aee9aaf commit 2a2cd06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ edition = "2021"
authors = ["Fergus Rorke <fergusjr@proton.me>"]

[features]
default = ["signed_cookies", "ssl"]
default = ["signed_cookies", "ssl", "tracing_subscriber"]
ssl = ["dep:axum-server"]
signed_cookies = []
console_subscriber = ["dep:console-subscriber"]
tracing_subscriber = ["dep:tracing-subscriber"]

[profile.release]
opt-level = 3
Expand All @@ -30,6 +32,7 @@ axum-server = { version = "0.7.1", default-features = false, features = ["tokio-
# Serde
serde = "1.0.204"
serde_json = "1.0.120"
serde_with = "3.10.0"
tokio-serde = { version = "0.9.0", features = ["json"] }
hex = "0.4.3"
base64 = "0.22.1"
Expand All @@ -45,7 +48,8 @@ deadpool-redis = "0.16.0"

# Logging
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"], optional = true }
console-subscriber = { version = "0.4.0", optional = true }

# Cryptography
argon2 = "0.5.3"
Expand All @@ -67,9 +71,7 @@ dotenv = "0.15.0"
image = "0.25.2"
fast_image_resize = "4.2.1"
futures-util = "0.3.30"
console-subscriber = "0.4.0"
tera = "1.20.0"
slugify = "0.1.0"
serde_with = "3.10.0"


7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ use auth::AuthManagerLayer;
use axum::{Extension, Router};

#[cfg(feature = "ssl")]
use axum_server::tls_rustls::RustlsConfig;
use ::{
axum_server::tls_rustls::RustlsConfig,
std::{net::SocketAddr, path::PathBuf},
};

use deadpool_redis::Pool as RedisPool;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use std::{error::Error, net::SocketAddr, path::PathBuf, sync::Arc};
use std::{error::Error, sync::Arc};
use tera::Tera;
use time::Duration;
use tokio::sync::Mutex;
Expand Down
38 changes: 16 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ use deadpool_redis::{Config as RedisConfig, Pool as RedisPool, Runtime};
use sqlx::{postgres::PgPoolOptions, Postgres};
use tera::Tera;
use tokio::sync::Mutex;

#[cfg(feature = "tracing_subscriber")]
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
//use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

type DbPool = sqlx::Pool<Postgres>;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
#[cfg(all(feature = "console_subscriber", feature = "tracing_subscriber"))]
compile_error!("Only one of `console_subscriber` and `tracing_subscriber` can be enabled!");

// Initiate logging
#[cfg(feature = "tracing_subscriber")]
tracing_subscriber::registry()
.with(EnvFilter::new(std::env::var("RUST_LOG").unwrap_or_else(
#[cfg(debug_assertions)]
Expand All @@ -44,27 +49,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
)
.try_init()?;

//console_subscriber::Builder::default()
// .filter_env_var(
// std::env::var("RUST_LOG").unwrap_or_else(
// #[cfg(debug_assertions)]
// |_| "trace,sqlx=info,fred=info,tokio=trace,runtime=trace".into(),
// #[cfg(not(debug_assertions))]
// |_| "info,sqlx=info,fred=info".into(),
// ), //.with(
// // #[cfg(debug_assertions)]
// // tracing_subscriber::fmt::layer()
// // .pretty()
// // .with_file(true)
// // .with_line_number(true)
// // .with_thread_ids(true),
// // #[cfg(not(debug_assertions))]
// // tracing_subscriber::fmt::layer()
// // .compact()
// // .with_thread_ids(true),
// )
// .server_addr(([127, 0, 0, 1], 5555))
// .init();
#[cfg(feature = "console_subscriber")]
console_subscriber::Builder::default()
.filter_env_var(std::env::var("RUST_LOG").unwrap_or_else(
#[cfg(debug_assertions)]
|_| "trace,sqlx=info,fred=info,tokio=trace,runtime=trace".into(),
#[cfg(not(debug_assertions))]
|_| "info,sqlx=info,fred=info".into(),
))
.server_addr(([127, 0, 0, 1], 5555))
.init();

let db = init_db().await?;
let redis_pool = init_redis()?;
Expand Down

0 comments on commit 2a2cd06

Please sign in to comment.