Skip to content

Commit 1ff2e0f

Browse files
committed
refactor: Reduce logging boiler plate
1 parent fb8764b commit 1ff2e0f

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1.0", features = ["serde_derive"] }
1212
serde_json = "1.0"
1313
tokio = { version = "1", features = ["full"] }
1414
axum = { version = "0.6.18", features = ["headers", "http1", "json", "tokio", "query"] }
15-
log = { version = "0.4", optional = true }
15+
log = "0.4"
1616
env_logger = { version = "0.11.8", optional = true }
1717
chrono = { version = "0.4", optional = true }
1818
clap = { version = "4.5.53", features = ["color", "derive", "help", "usage", "std", "env"] }
@@ -24,6 +24,6 @@ tower = "0.4"
2424

2525
[features]
2626
default = ["logging"]
27-
logging = ["dep:log", "dep:env_logger"]
27+
logging = ["dep:env_logger"]
2828
json-logging = ["dep:chrono", "logging"]
2929
redis = []

src/main.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ async fn main() {
2121
init_logs(&cfg);
2222

2323
if cfg.api_key().is_none() {
24-
#[cfg(feature = "logging")]
2524
log::warn!("No API key is configured, authentication is disabled");
2625
}
2726

@@ -36,7 +35,6 @@ async fn main() {
3635
.with_state(state);
3736

3837
let addr: SocketAddr = cfg.address().unwrap();
39-
#[cfg(feature = "logging")]
4038
log::info!("Running flagpole on {:?}", addr);
4139

4240
axum::Server::bind(&addr)
@@ -45,7 +43,6 @@ async fn main() {
4543
.await
4644
.unwrap();
4745

48-
#[cfg(feature = "logging")]
4946
log::info!("Server shutdown complete");
5047
}
5148

@@ -94,11 +91,9 @@ async fn shutdown_signal() {
9491

9592
tokio::select! {
9693
_ = ctrl_c => {
97-
#[cfg(feature = "logging")]
9894
log::info!("Received SIGINT (CTRL+C), initiating graceful shutdown");
9995
},
10096
_ = terminate => {
101-
#[cfg(feature = "logging")]
10297
log::info!("Received SIGTERM, initiating graceful shutdown");
10398
},
10499
}
@@ -148,7 +143,6 @@ async fn put_flag(
148143
}
149144
let updated: bool = state.0.db.write().unwrap().set_value(&namespace, flag.clone()).unwrap();
150145
if updated {
151-
#[cfg(feature = "logging")]
152146
log::info!("Flag '{flag}' enabled in namespace <<{namespace}>>");
153147
}
154148
StatusCode::NO_CONTENT
@@ -164,7 +158,6 @@ async fn delete_flag(
164158
}
165159
let updated: bool = state.0.db.write().unwrap().delete_flag(&namespace, flag.clone()).unwrap();
166160
if updated {
167-
#[cfg(feature = "logging")]
168161
log::info!("Flag {flag} disabled in namespace {namespace}");
169162
}
170163
StatusCode::NO_CONTENT

0 commit comments

Comments
 (0)