File: 2003_no_env-filter.patch

package info (click to toggle)
edu-sync 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 492 kB
  • sloc: makefile: 36; sh: 1
file content (58 lines) | stat: -rw-r--r-- 1,869 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Description: avoid not-in-Debian tracing-subscriber feature "env-filter"
Author: Jonas Smedegaard <dr@jones.dk>
https://bugs.debian.org/1053420
Forwarded: not-needed
Last-Update: 2024-09-29
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/edu-sync-cli/Cargo.toml
+++ b/edu-sync-cli/Cargo.toml
@@ -21,5 +21,5 @@
 portable-atomic = "1"
 tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
 tracing = "0.1"
-tracing-subscriber = { version = "0.3", features = ["env-filter"] }
+tracing-subscriber = "0.3"
 url = "2.2"
--- a/edu-sync-cli/src/main.rs
+++ b/edu-sync-cli/src/main.rs
@@ -16,7 +16,7 @@
 
 use clap::Parser;
 use human_panic::setup_panic;
-use tracing_subscriber::EnvFilter;
+use tracing_subscriber::filter::LevelFilter;
 
 #[derive(Debug, clap::Parser)]
 #[clap(name = "Edu Sync", author, about)]
@@ -40,13 +40,23 @@
 
 #[tokio::main]
 async fn main() -> anyhow::Result<()> {
-    let fmt = tracing_subscriber::fmt().with_writer(std::io::stderr);
-    if env::var_os(EnvFilter::DEFAULT_ENV).is_some() {
-        fmt.with_env_filter(EnvFilter::try_from_default_env()?)
-            .init();
-    } else {
-        fmt.init();
-    }
+    let filter = match std::env::var("RUST_LOG") {
+        Ok(val) => {
+            if val.contains("debug") {
+                LevelFilter::DEBUG
+            } else if val.contains("info") {
+                LevelFilter::INFO
+            } else if val.contains("warn") {
+                LevelFilter::WARN
+            } else if val.contains("error") {
+                LevelFilter::ERROR
+            } else {
+                LevelFilter::ERROR
+            }
+        },
+        Err(_) => LevelFilter::ERROR,
+    };
+    tracing_subscriber::fmt().with_max_level(filter).with_writer(std::io::stderr).init();
     setup_panic!();
 
     Subcommand::parse().run().await