Skip to content

Commit 3d729b3

Browse files
committed
refactor: remove tracing codes
1 parent 6cdb58e commit 3d729b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+47
-584
lines changed

Cargo.toml

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ chrono = "0.4.38"
3131
rustix = { version = "1", features = ["process", "stdio"] }
3232
libc = "0.2.159"
3333
reqwest = { version = "0.12.8", default-features = false }
34-
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", features = [
34+
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev", features = [
3535
"multi-thread",
3636
"source-location",
3737
], optional = true }
@@ -56,7 +56,6 @@ clap_complete = { version = "4.5", features = ["unstable-dynamic"] }
5656
clap_lex = "0.7.4"
5757
fs4 = "0.13.1"
5858
fs_extra = "1.3.0"
59-
tracing-appender = { version = "0.2.3", optional = true }
6059
dirs = "6.0.0"
6160
termtree = "0.5.1"
6261
textwrap = "0.16.2"
@@ -107,38 +106,6 @@ openssl = [
107106
]
108107
nice-setup = ["sequoia-nettle-backend", "rustls", "oma-refresh/apt"]
109108
openssl-setup = ["sequoia-openssl-backend", "openssl", "oma-refresh/apt"]
110-
spdlog-rs = [
111-
"dep:spdlog-rs",
112-
"oma-utils/spdlog-rs",
113-
"oma-console/spdlog-rs",
114-
"oma-pm/spdlog-rs",
115-
"oma-refresh/spdlog-rs",
116-
"oma-contents/spdlog-rs",
117-
"oma-fetch/spdlog-rs",
118-
"oma-topics/spdlog-rs",
119-
"oma-history/spdlog-rs",
120-
"oma-repo-verify/spdlog-rs",
121-
"oma-mirror/spdlog-rs",
122-
"apt-auth-config/spdlog-rs",
123-
"oma-tum/spdlog-rs",
124-
]
125-
tracing = [
126-
"dep:tracing",
127-
"dep:tracing-subscriber",
128-
"dep:tracing-appender",
129-
"oma-utils/tracing",
130-
"oma-console/tracing",
131-
"oma-pm/tracing",
132-
"oma-refresh/tracing",
133-
"oma-contents/tracing",
134-
"oma-fetch/tracing",
135-
"oma-topics/tracing",
136-
"oma-history/tracing",
137-
"oma-repo-verify/tracing",
138-
"oma-mirror/tracing",
139-
"apt-auth-config/tracing",
140-
"oma-tum/tracing",
141-
]
142109
default = ["aosc", "nice-setup"]
143110

144111
[workspace]

apt-auth-config/Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ license = "MIT"
77

88
[dependencies]
99
thiserror = "2"
10-
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true }
11-
tracing = { version = "0.1", optional = true }
10+
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" }
1211
rust-netrc = "0.1"
1312
url = "2.5"
14-
15-
[features]
16-
spdlog-rs = ["dep:spdlog-rs"]
17-
tracing = ["dep:tracing"]

oma-console/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ license = "MIT"
1111
chrono = { version = "0.4.38", optional = true }
1212
console = { version = "0.16", optional = true }
1313
indicatif = { version = "0.18", optional = true }
14-
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true }
15-
tracing = { version = "0.1", optional = true }
16-
tracing-subscriber = { version = "0.3", optional = true }
14+
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" }
1715
ratatui = { version = "0.29", optional = true }
1816
# https://github.com/async-rs/async-std/issues/1055
1917
# https://github.com/tokio-rs/tokio/issues/5535
@@ -23,9 +21,7 @@ textwrap = { version = "0.16", optional = true }
2321
aho-corasick = { version = "1.1.3", optional = true }
2422

2523
[features]
26-
tracing = ["dep:tracing", "dep:tracing-subscriber"]
2724
print = ["dep:textwrap", "dep:console", "dep:termbg", "dep:chrono"]
2825
pager = ["dep:ratatui", "dep:ansi-to-tui", "dep:console", "dep:aho-corasick"]
2926
progress_bar_style = ["dep:indicatif"]
30-
spdlog-rs = ["dep:spdlog-rs"]
3127
default = ["print", "pager", "progress_bar_style"]

oma-console/examples/msg.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
#[cfg(feature = "spdlog-rs")]
21
use oma_console::OmaFormatter;
32

4-
#[cfg(not(feature = "spdlog-rs"))]
5-
use oma_console::OmaLayer;
6-
#[cfg(not(feature = "spdlog-rs"))]
7-
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt};
8-
9-
#[cfg(not(feature = "spdlog-rs"))]
10-
fn main() {
11-
tracing_subscriber::registry().with(OmaLayer::new()).init();
12-
tracing::info!("Welcome");
13-
tracing::debug!("Hello");
14-
tracing::info!("I'am fine");
15-
tracing::warn!("Thank you");
16-
tracing::error!("and you?");
17-
}
18-
19-
#[cfg(feature = "spdlog-rs")]
203
fn main() {
214
spdlog::default_logger()
225
.sinks()

oma-console/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ pub mod writer;
2929
#[cfg(feature = "print")]
3030
pub mod print;
3131

32-
#[cfg(not(all(feature = "print", feature = "spdlog-rs")))]
33-
pub use print::OmaLayer;
34-
35-
#[cfg(all(feature = "print", feature = "spdlog-rs"))]
32+
#[cfg(feature = "print")]
3633
pub use print::OmaFormatter;
3734

3835
#[cfg(feature = "print")]

oma-console/src/pager.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ use ratatui::{
2222
},
2323
widgets::Borders,
2424
};
25-
#[cfg(feature = "spdlog-rs")]
2625
use spdlog::debug;
2726
use termbg::Theme;
28-
#[cfg(not(feature = "spdlog-rs"))]
29-
use tracing::debug;
3027

3128
use crate::{print::OmaColorFormat, writer::Writer};
3229

oma-console/src/print.rs

Lines changed: 19 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
#[cfg(not(feature = "spdlog-rs"))]
2-
use std::collections::BTreeMap;
3-
#[cfg(feature = "spdlog-rs")]
41
use std::fmt::{self, Write};
5-
62
use std::{borrow::Cow, time::Duration};
73

8-
#[cfg(feature = "spdlog-rs")]
94
use chrono::{DateTime, SecondsFormat, Utc};
105
use console::{Color, StyledObject, style};
11-
#[cfg(feature = "spdlog-rs")]
126
use spdlog::{Level, debug, formatter::Formatter};
137
use termbg::Theme;
14-
#[cfg(not(feature = "spdlog-rs"))]
15-
use tracing::{Level, debug, field::Field};
16-
#[cfg(not(feature = "spdlog-rs"))]
17-
use tracing_subscriber::Layer;
188

199
pub use termbg;
2010

21-
#[cfg(feature = "spdlog-rs")]
2211
use crate::writer::gen_prefix;
23-
#[cfg(not(feature = "spdlog-rs"))]
24-
use crate::writer::{Writeln, Writer};
2512

2613
#[derive(Clone)]
2714
enum StyleFollow {
@@ -146,7 +133,25 @@ fn term_color<D>(input: D, color: Action) -> StyledObject<D> {
146133
}
147134
}
148135

149-
#[cfg(feature = "spdlog-rs")]
136+
/// OmaFormatter
137+
/// `OmaFormatter` is used for outputting oma-style logs to `spdlog-rs`
138+
///
139+
/// # Example:
140+
/// ```
141+
/// use spdlog::{info, sink::StdStreamSink, Logger};
142+
/// use oma_console::OmaLayer;
143+
///
144+
/// let mut logger_builder = Logger::builder();
145+
///
146+
/// let logger = logger_builder.sink(Arc::new(
147+
/// StdStreamSink::builder().formatter(Box::new(OmaLayer::default())).build().unwrap()
148+
/// )).build().unwrap();
149+
///
150+
/// spdlog::set_default_logger(Arc::new(logger));
151+
///
152+
/// info!("My name is oma!");
153+
/// ```
154+
///
150155
#[derive(Clone)]
151156
pub struct OmaFormatter {
152157
with_ansi: bool,
@@ -155,7 +160,6 @@ pub struct OmaFormatter {
155160
prefix_len: u16,
156161
}
157162

158-
#[cfg(feature = "spdlog-rs")]
159163
impl Default for OmaFormatter {
160164
fn default() -> Self {
161165
Self {
@@ -167,7 +171,6 @@ impl Default for OmaFormatter {
167171
}
168172
}
169173

170-
#[cfg(feature = "spdlog-rs")]
171174
impl OmaFormatter {
172175
pub fn new() -> Self {
173176
OmaFormatter::default()
@@ -267,7 +270,6 @@ impl OmaFormatter {
267270
}
268271
}
269272

270-
#[cfg(feature = "spdlog-rs")]
271273
impl Formatter for OmaFormatter {
272274
fn format(
273275
&self,
@@ -279,147 +281,3 @@ impl Formatter for OmaFormatter {
279281
.map_err(|e| spdlog::Error::FormatRecord(e))
280282
}
281283
}
282-
283-
/// OmaLayer
284-
/// `OmaLayer` is used for outputting oma-style logs to `tracing`
285-
///
286-
/// # Example:
287-
/// ```
288-
/// use tracing_subscriber::prelude::*;
289-
/// use oma_console::OmaLayer;
290-
/// use tracing::info;
291-
///
292-
/// tracing_subscriber::registry()
293-
/// .with(OmaLayer::new())
294-
/// .init();
295-
///
296-
/// info!("My name is oma!");
297-
/// ```
298-
///
299-
#[cfg(not(feature = "spdlog-rs"))]
300-
pub struct OmaLayer {
301-
/// Display result with ansi
302-
with_ansi: bool,
303-
/// A Terminal writer to print oma-style message
304-
writer: Writer,
305-
}
306-
307-
#[cfg(not(feature = "spdlog-rs"))]
308-
impl Default for OmaLayer {
309-
fn default() -> Self {
310-
Self {
311-
with_ansi: true,
312-
#[cfg(not(feature = "spdlog-rs"))]
313-
writer: Writer::default(),
314-
}
315-
}
316-
}
317-
318-
#[cfg(not(feature = "spdlog-rs"))]
319-
impl OmaLayer {
320-
pub fn new() -> Self {
321-
OmaLayer::default()
322-
}
323-
324-
/// Display with ANSI colors
325-
///
326-
/// Set to false to disable ANSI color sequences.
327-
pub fn with_ansi(mut self, with_ansi: bool) -> Self {
328-
self.with_ansi = with_ansi;
329-
self
330-
}
331-
}
332-
333-
#[cfg(not(feature = "spdlog-rs"))]
334-
impl<S> Layer<S> for OmaLayer
335-
where
336-
S: tracing::Subscriber,
337-
S: for<'lookup> tracing_subscriber::registry::LookupSpan<'lookup>,
338-
{
339-
fn on_event(
340-
&self,
341-
event: &tracing::Event<'_>,
342-
_ctx: tracing_subscriber::layer::Context<'_, S>,
343-
) {
344-
let level = *event.metadata().level();
345-
346-
let prefix = if self.with_ansi {
347-
Cow::Owned(match level {
348-
Level::DEBUG => console::style("DEBUG").dim().to_string(),
349-
Level::INFO => console::style("INFO").blue().bold().to_string(),
350-
Level::WARN => console::style("WARNING").yellow().bold().to_string(),
351-
Level::ERROR => console::style("ERROR").red().bold().to_string(),
352-
Level::TRACE => console::style("TRACE").dim().to_string(),
353-
})
354-
} else {
355-
Cow::Borrowed(match level {
356-
Level::DEBUG => "DEBUG",
357-
Level::INFO => "INFO",
358-
Level::WARN => "WARNING",
359-
Level::ERROR => "ERROR",
360-
Level::TRACE => "TRACE",
361-
})
362-
};
363-
364-
let mut visitor = OmaRecorder(BTreeMap::new());
365-
event.record(&mut visitor);
366-
367-
for (k, v) in visitor.0 {
368-
if k == "message" {
369-
if self.with_ansi {
370-
self.writer.writeln(&prefix, &v).ok();
371-
} else {
372-
self.writer
373-
.writeln(&prefix, &console::strip_ansi_codes(&v))
374-
.ok();
375-
}
376-
}
377-
}
378-
}
379-
}
380-
/// OmaRecorder
381-
/// `OmaRecorder` is used for recording oma-style logs.
382-
///
383-
/// # Example:
384-
/// ```ignore
385-
/// let mut visitor = OmaRecorder(BTreeMap::new());
386-
/// event.record(&mut visitor);
387-
/// for (k, v) in visitor.0 {
388-
/// if k == "message" {
389-
/// self.writer.writeln(&prefix, &v).ok();
390-
/// }
391-
/// }
392-
/// ```
393-
#[cfg(not(feature = "spdlog-rs"))]
394-
struct OmaRecorder<'a>(BTreeMap<&'a str, String>);
395-
396-
#[cfg(not(feature = "spdlog-rs"))]
397-
impl tracing::field::Visit for OmaRecorder<'_> {
398-
fn record_f64(&mut self, field: &Field, value: f64) {
399-
self.0.insert(field.name(), value.to_string());
400-
}
401-
402-
fn record_i64(&mut self, field: &Field, value: i64) {
403-
self.0.insert(field.name(), value.to_string());
404-
}
405-
406-
fn record_u64(&mut self, field: &Field, value: u64) {
407-
self.0.insert(field.name(), value.to_string());
408-
}
409-
410-
fn record_bool(&mut self, field: &Field, value: bool) {
411-
self.0.insert(field.name(), value.to_string());
412-
}
413-
414-
fn record_str(&mut self, field: &Field, value: &str) {
415-
self.0.insert(field.name(), value.to_string());
416-
}
417-
418-
fn record_error(&mut self, field: &Field, value: &(dyn std::error::Error + 'static)) {
419-
self.0.insert(field.name(), format!("{value:#?}"));
420-
}
421-
422-
fn record_debug(&mut self, field: &Field, value: &dyn std::fmt::Debug) {
423-
self.0.insert(field.name(), format!("{value:#?}"));
424-
}
425-
}

oma-contents/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ winnow = "0.7"
1414
flate2 = "1.0"
1515
rayon = "1.8"
1616
lzzzz = "2.0"
17-
tracing = { version = "0.1", optional = true }
18-
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true }
17+
spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" }
1918
which = "8"
2019
zstd = "0.13"
2120
memchr = "2"
2221

2322
[features]
2423
aosc = []
25-
spdlog-rs = ["dep:spdlog-rs"]
26-
tracing = ["dep:tracing"]

oma-contents/src/searcher.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use flate2::bufread::GzDecoder;
1414
use lzzzz::lz4f::BufReadDecompressor;
1515
use memchr::memmem;
1616
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
17-
#[cfg(feature = "spdlog-rs")]
1817
use spdlog::debug;
19-
#[cfg(not(feature = "spdlog-rs"))]
20-
use tracing::debug;
2118
use zstd::Decoder;
2219

2320
use crate::{OmaContentsError, parser::parse_contents_single_line};

0 commit comments

Comments
 (0)