From 75a980a54411402c1c268b0edcc8f12345ed5bac Mon Sep 17 00:00:00 2001 From: Neko Date: Fri, 5 Sep 2025 15:14:57 +0800 Subject: [PATCH 1/9] refactor: refactor to spdlog-rs instead of tracing --- .gitignore | 2 +- Cargo.lock | 407 ++++++++++++++++++++++++---- Cargo.toml | 88 +++++- apt-auth-config/Cargo.toml | 7 +- oma-console/Cargo.toml | 8 +- oma-console/examples/msg.rs | 21 ++ oma-console/src/lib.rs | 5 +- oma-console/src/pager.rs | 3 + oma-console/src/print.rs | 158 ++++++++++- oma-contents/Cargo.toml | 5 +- oma-contents/src/parser.rs | 2 +- oma-contents/src/searcher.rs | 3 + oma-fetch/Cargo.toml | 5 +- oma-fetch/src/download.rs | 3 + oma-fetch/src/lib.rs | 3 + oma-history/Cargo.toml | 7 +- oma-history/src/lib.rs | 3 + oma-history/src/migrations.rs | 3 + oma-mirror/Cargo.toml | 7 +- oma-mirror/src/lib.rs | 3 + oma-pm/Cargo.toml | 9 +- oma-pm/src/apt.rs | 7 +- oma-pm/src/commit.rs | 3 + oma-pm/src/dbus.rs | 3 + oma-pm/src/download.rs | 3 + oma-pm/src/matches.rs | 3 + oma-pm/src/utils.rs | 8 +- oma-refresh/Cargo.toml | 15 +- oma-refresh/src/config.rs | 3 + oma-refresh/src/db.rs | 5 +- oma-refresh/src/inrelease.rs | 3 + oma-refresh/src/sourceslist.rs | 7 +- oma-repo-verify/Cargo.toml | 5 +- oma-repo-verify/src/lib.rs | 3 + oma-topics/Cargo.toml | 16 +- oma-topics/src/lib.rs | 3 + oma-tum/Cargo.toml | 7 +- oma-tum/src/lib.rs | 3 + oma-utils/Cargo.toml | 3 +- oma-utils/src/dbus/mod.rs | 2 +- oma-utils/src/dpkg/mod.rs | 3 + src/config.rs | 7 +- src/error.rs | 3 + src/main.rs | 114 +++++++- src/path_completions.rs | 3 + src/pb.rs | 5 +- src/subcommand/clean.rs | 7 +- src/subcommand/command_not_found.rs | 3 + src/subcommand/download.rs | 3 + src/subcommand/history.rs | 4 +- src/subcommand/install.rs | 6 +- src/subcommand/list.rs | 3 + src/subcommand/mark.rs | 3 + src/subcommand/mirror.rs | 6 +- src/subcommand/refresh.rs | 3 + src/subcommand/remove.rs | 3 + src/subcommand/show.rs | 3 + src/subcommand/size_analyzer.rs | 3 + src/subcommand/topics.rs | 3 + src/subcommand/upgrade.rs | 7 +- src/subcommand/utils.rs | 8 +- src/tui/mod.rs | 3 + src/utils.rs | 12 + 63 files changed, 947 insertions(+), 122 deletions(-) diff --git a/.gitignore b/.gitignore index 3d7bdb86f..8e8cb4a7f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ test /oma-fetcher-test /*.deb /completions -/man \ No newline at end of file +/man diff --git a/Cargo.lock b/Cargo.lock index 3ff964aef..7a1c98b13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,6 +147,7 @@ name = "apt-auth-config" version = "0.4.0" dependencies = [ "rust-netrc", + "spdlog-rs", "thiserror 2.0.17", "tracing", "url", @@ -296,7 +297,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -336,7 +337,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -353,9 +354,15 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] +[[package]] +name = "atomic" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" + [[package]] name = "atomic-waker" version = "1.1.2" @@ -478,7 +485,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn", + "syn 2.0.106", ] [[package]] @@ -570,7 +577,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.106", ] [[package]] @@ -753,10 +760,10 @@ version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -907,6 +914,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + [[package]] name = "crossbeam-channel" version = "0.5.15" @@ -935,6 +955,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -1020,7 +1049,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.106", ] [[package]] @@ -1034,7 +1063,7 @@ dependencies = [ "indexmap 2.11.4", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1053,7 +1082,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.106", ] [[package]] @@ -1087,7 +1116,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.106", ] [[package]] @@ -1101,7 +1130,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.106", ] [[package]] @@ -1112,7 +1141,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ "darling_core 0.20.11", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1123,7 +1152,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" dependencies = [ "darling_core 0.21.3", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1134,7 +1163,7 @@ checksum = "86bf2d0fa4ce2457e94bd7efb15aeadc115297f04b660bd0da706729e0d91442" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1256,7 +1285,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1301,7 +1330,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1322,7 +1351,7 @@ checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1337,6 +1366,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "erased-serde" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e004d887f51fcb9fef17317a2f3525c887d8aa3f4f50fed920816a688284a5b7" +dependencies = [ + "serde", + "typeid", +] + [[package]] name = "errno" version = "0.3.14" @@ -1622,7 +1661,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -1826,6 +1865,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -2039,7 +2084,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.106", "unic-langid", ] @@ -2053,7 +2098,7 @@ dependencies = [ "i18n-config", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -2193,6 +2238,12 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "if_chain" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd62e6b5e86ea8eeeb8db1de02880a6abc01a397b2ebb64b5d74ac255318f5cb" + [[package]] name = "indexmap" version = "1.9.3" @@ -2257,7 +2308,7 @@ dependencies = [ "indoc", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -2306,6 +2357,17 @@ dependencies = [ "serde", ] +[[package]] +name = "is-terminal" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_executable" version = "1.0.5" @@ -2433,7 +2495,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn", + "syn 2.0.106", ] [[package]] @@ -2579,7 +2641,7 @@ dependencies = [ "quote", "regex-syntax", "rustc_version", - "syn", + "syn 2.0.106", ] [[package]] @@ -2867,7 +2929,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -2955,6 +3017,7 @@ dependencies = [ "serde", "serde_json", "sha2", + "spdlog-rs", "strsim", "sysinfo", "tabled", @@ -2997,9 +3060,11 @@ version = "0.29.1" dependencies = [ "aho-corasick", "ansi-to-tui", + "chrono", "console", "indicatif", "ratatui", + "spdlog-rs", "termbg-with-async-stdin", "textwrap", "tracing", @@ -3015,6 +3080,7 @@ dependencies = [ "memchr", "rayon", "regex", + "spdlog-rs", "thiserror 2.0.17", "tracing", "which", @@ -3037,6 +3103,7 @@ dependencies = [ "serde", "sha2", "snafu", + "spdlog-rs", "tokio", "tokio-util", "tracing", @@ -3051,6 +3118,7 @@ dependencies = [ "rusqlite", "serde", "serde_json", + "spdlog-rs", "thiserror 2.0.17", "tracing", ] @@ -3081,6 +3149,7 @@ dependencies = [ "serde", "serde_json", "snafu", + "spdlog-rs", "toml 0.9.8", "tracing", ] @@ -3107,6 +3176,7 @@ dependencies = [ "oma-utils", "once_cell", "serde", + "spdlog-rs", "strsim", "sysinfo", "thiserror 2.0.17", @@ -3146,6 +3216,7 @@ dependencies = [ "oma-topics", "oma-utils", "once_cell", + "spdlog-rs", "sys-locale", "sysinfo", "thiserror 2.0.17", @@ -3162,6 +3233,7 @@ dependencies = [ "oma-apt-sources-lists", "sequoia-openpgp", "sequoia-policy-config", + "spdlog-rs", "thiserror 2.0.17", "tracing", ] @@ -3178,6 +3250,7 @@ dependencies = [ "reqwest", "serde", "serde_json", + "spdlog-rs", "thiserror 2.0.17", "tokio", "tracing", @@ -3195,6 +3268,7 @@ dependencies = [ "serde", "serde_json", "snafu", + "spdlog-rs", "tracing", "tracing-subscriber", ] @@ -3206,6 +3280,7 @@ dependencies = [ "logind-zbus", "number_prefix", "os-release", + "spdlog-rs", "thiserror 2.0.17", "tracing", "url-escape", @@ -3247,7 +3322,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -3403,7 +3478,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -3492,7 +3567,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.106", ] [[package]] @@ -3523,7 +3598,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -3555,7 +3630,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -3723,7 +3798,7 @@ dependencies = [ "itertools 0.13.0", "lru", "paste", - "strum", + "strum 0.26.3", "unicode-segmentation", "unicode-truncate", "unicode-width 0.2.0", @@ -3920,7 +3995,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn", + "syn 2.0.106", "walkdir", ] @@ -4161,6 +4236,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_buf" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a86be9d6c7d34718d2ec6f56c8d6a4671d1a7357c2a6921f47fe5a3ee6056cc" +dependencies = [ + "serde", +] + [[package]] name = "serde_core" version = "1.0.228" @@ -4178,7 +4262,16 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", +] + +[[package]] +name = "serde_fmt" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d4ddca14104cd60529e8c7f7ba71a2c8acd8f7f5cfcdc2faf97eeb7c3010a4" +dependencies = [ + "serde", ] [[package]] @@ -4202,7 +4295,7 @@ checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -4360,10 +4453,10 @@ version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1c97747dbf44bb1ca44a561ece23508e99cb592e862f22222dcf42f51d1e451" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -4386,6 +4479,52 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "spdlog-internal" +version = "0.1.0" +source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=sink-decouple#6bcb3571d40426443cf764641bc2bc126a08fc24" +dependencies = [ + "nom", + "strum 0.24.1", + "strum_macros 0.24.3", + "thiserror 1.0.69", +] + +[[package]] +name = "spdlog-macros" +version = "0.2.0" +source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=sink-decouple#6bcb3571d40426443cf764641bc2bc126a08fc24" +dependencies = [ + "nom", + "proc-macro2", + "quote", + "spdlog-internal", + "syn 2.0.106", +] + +[[package]] +name = "spdlog-rs" +version = "0.4.3" +source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=sink-decouple#6bcb3571d40426443cf764641bc2bc126a08fc24" +dependencies = [ + "arc-swap", + "atomic", + "cfg-if", + "chrono", + "crossbeam", + "dyn-clone", + "if_chain", + "is-terminal", + "libc", + "once_cell", + "parking_lot", + "rustc_version", + "spdlog-macros", + "thiserror 1.0.69", + "value-bag", + "winapi", +] + [[package]] name = "spin" version = "0.9.8" @@ -4425,13 +4564,35 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros 0.24.3", +] + [[package]] name = "strum" version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ - "strum_macros", + "strum_macros 0.26.4", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "rustversion", + "syn 1.0.109", ] [[package]] @@ -4440,11 +4601,11 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.106", ] [[package]] @@ -4453,6 +4614,95 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "sval" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc9739f56c5d0c44a5ed45473ec868af02eb896af8c05f616673a31e1d1bb09" + +[[package]] +name = "sval_buffer" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f39b07436a8c271b34dad5070c634d1d3d76d6776e938ee97b4a66a5e8003d0b" +dependencies = [ + "sval", + "sval_ref", +] + +[[package]] +name = "sval_dynamic" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffcb072d857431bf885580dacecf05ed987bac931230736739a79051dbf3499b" +dependencies = [ + "sval", +] + +[[package]] +name = "sval_fmt" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f214f427ad94a553e5ca5514c95c6be84667cbc5568cce957f03f3477d03d5c" +dependencies = [ + "itoa", + "ryu", + "sval", +] + +[[package]] +name = "sval_json" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ed34b32e638dec9a99c8ac92d0aa1220d40041026b625474c2b6a4d6f4feb" +dependencies = [ + "itoa", + "ryu", + "sval", +] + +[[package]] +name = "sval_nested" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14bae8fcb2f24fee2c42c1f19037707f7c9a29a0cda936d2188d48a961c4bb2a" +dependencies = [ + "sval", + "sval_buffer", + "sval_ref", +] + +[[package]] +name = "sval_ref" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a4eaea3821d3046dcba81d4b8489421da42961889902342691fb7eab491d79e" +dependencies = [ + "sval", +] + +[[package]] +name = "sval_serde" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "172dd4aa8cb3b45c8ac8f3b4111d644cd26938b0643ede8f93070812b87fb339" +dependencies = [ + "serde", + "sval", + "sval_nested", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.106" @@ -4481,7 +4731,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -4526,11 +4776,11 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ea5d1b13ca6cff1f9231ffd62f15eefd72543dab5e468735f1a456728a02846" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro-error2", "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -4649,7 +4899,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -4660,7 +4910,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -4765,7 +5015,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -4999,7 +5249,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -5056,6 +5306,12 @@ dependencies = [ "rustc-hash 2.1.1", ] +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + [[package]] name = "typenum" version = "1.19.0" @@ -5190,6 +5446,43 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "value-bag" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943ce29a8a743eb10d6082545d861b24f9d1b160b7d741e0f2cdf726bec909c5" +dependencies = [ + "value-bag-serde1", + "value-bag-sval2", +] + +[[package]] +name = "value-bag-serde1" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35540706617d373b118d550d41f5dfe0b78a0c195dc13c6815e92e2638432306" +dependencies = [ + "erased-serde", + "serde", + "serde_buf", + "serde_fmt", +] + +[[package]] +name = "value-bag-sval2" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe7e140a2658cc16f7ee7a86e413e803fc8f9b5127adc8755c19f9fefa63a52" +dependencies = [ + "sval", + "sval_buffer", + "sval_dynamic", + "sval_fmt", + "sval_json", + "sval_ref", + "sval_serde", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -5278,7 +5571,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 2.0.106", "wasm-bindgen-shared", ] @@ -5313,7 +5606,7 @@ checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5478,7 +5771,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -5489,7 +5782,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -5777,7 +6070,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", "synstructure", ] @@ -5824,7 +6117,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.106", "zbus_names", "zvariant", "zvariant_utils", @@ -5859,7 +6152,7 @@ checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -5879,7 +6172,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", "synstructure", ] @@ -5919,7 +6212,7 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.106", ] [[package]] @@ -5973,7 +6266,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.106", "zvariant_utils", ] @@ -5986,6 +6279,6 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn", + "syn 2.0.106", "winnow", ] diff --git a/Cargo.toml b/Cargo.toml index cbb189647..2aae8efd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,14 @@ authors = ["eatradish "] [dependencies] # Cli -clap = { version = "4.5.19", features = ["cargo", "wrap_help", "color", "derive", "env", "string"] } +clap = { version = "4.5.19", features = [ + "cargo", + "wrap_help", + "color", + "derive", + "env", + "string", +] } anyhow = "1.0.89" ctrlc = "3.4.5" dialoguer = "0.12.0" @@ -24,8 +31,14 @@ chrono = "0.4.38" rustix = { version = "1", features = ["process", "stdio"] } libc = "0.2.159" reqwest = { version = "0.12.8", default-features = false } -tracing = "0.1.40" -tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", features = [ + "multi-thread", + "source-location", +], optional = true } +tracing = { version = "0.1.40", optional = true } +tracing-subscriber = { version = "0.3.18", features = [ + "env-filter", +], optional = true } console-subscriber = { version = "0.4.0", optional = true } ratatui = "0.29.0" ansi-to-tui = "7.0.0" @@ -43,7 +56,7 @@ clap_complete = { version = "4.5", features = ["unstable-dynamic"] } clap_lex = "0.7.4" fs4 = "0.13.1" fs_extra = "1.3.0" -tracing-appender = "0.2.3" +tracing-appender = { version = "0.2.3", optional = true } dirs = "6.0.0" termtree = "0.5.1" textwrap = "0.16.2" @@ -68,7 +81,10 @@ apt-auth-config = { path = "./apt-auth-config" } oma-tum = { path = "./oma-tum", optional = true } # i18n -i18n-embed = { version = "0.16.0", features = ["fluent-system", "desktop-requester"]} +i18n-embed = { version = "0.16.0", features = [ + "fluent-system", + "desktop-requester", +] } i18n-embed-fl = "0.10" rust-embed = "8.5.0" @@ -77,14 +93,70 @@ aosc = ["dep:oma-topics", "oma-refresh/aosc", "oma-pm/aosc", "oma-contents/aosc" sequoia-openssl-backend = ["oma-refresh/sequoia-openssl-backend"] sequoia-nettle-backend = ["oma-refresh/sequoia-nettle-backend"] tokio-console = ["dep:console-subscriber"] -rustls = ["reqwest/rustls-tls", "oma-fetch/rustls", "oma-refresh/rustls", "oma-topics/rustls"] -openssl = ["reqwest/native-tls", "oma-fetch/native-tls", "oma-refresh/native-tls", "oma-topics/native-tls"] +rustls = [ + "reqwest/rustls-tls", + "oma-fetch/rustls", + "oma-refresh/rustls", + "oma-topics/rustls", +] +openssl = [ + "reqwest/native-tls", + "oma-fetch/native-tls", + "oma-refresh/native-tls", + "oma-topics/native-tls", +] nice-setup = ["sequoia-nettle-backend", "rustls", "oma-refresh/apt"] openssl-setup = ["sequoia-openssl-backend", "openssl", "oma-refresh/apt"] +spdlog-rs = [ + "dep:spdlog-rs", + "oma-utils/spdlog-rs", + "oma-console/spdlog-rs", + "oma-pm/spdlog-rs", + "oma-refresh/spdlog-rs", + "oma-contents/spdlog-rs", + "oma-fetch/spdlog-rs", + "oma-topics/spdlog-rs", + "oma-history/spdlog-rs", + "oma-repo-verify/spdlog-rs", + "oma-mirror/spdlog-rs", + "apt-auth-config/spdlog-rs", + "oma-tum/spdlog-rs", +] +tracing = [ + "dep:tracing", + "dep:tracing-subscriber", + "dep:tracing-appender", + "oma-utils/tracing", + "oma-console/tracing", + "oma-pm/tracing", + "oma-refresh/tracing", + "oma-contents/tracing", + "oma-fetch/tracing", + "oma-topics/tracing", + "oma-history/tracing", + "oma-repo-verify/tracing", + "oma-mirror/tracing", + "apt-auth-config/tracing", + "oma-tum/tracing", +] default = ["aosc", "nice-setup"] [workspace] -members = ["oma-contents", "oma-console", "oma-topics", "oma-fetch", "oma-refresh", "oma-utils", "oma-pm", "oma-history", "oma-pm-operation-type", "oma-repo-verify", "oma-mirror", "apt-auth-config", "oma-tum"] +members = [ + "oma-contents", + "oma-console", + "oma-topics", + "oma-fetch", + "oma-refresh", + "oma-utils", + "oma-pm", + "oma-history", + "oma-pm-operation-type", + "oma-repo-verify", + "oma-mirror", + "apt-auth-config", + "oma-tum", +] [package.metadata.deb] copyright = "2025, AOSC Dev " diff --git a/apt-auth-config/Cargo.toml b/apt-auth-config/Cargo.toml index 4dcbbc2ca..8bce81f03 100644 --- a/apt-auth-config/Cargo.toml +++ b/apt-auth-config/Cargo.toml @@ -7,6 +7,11 @@ license = "MIT" [dependencies] thiserror = "2" -tracing = "0.1" +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +tracing = { version = "0.1", optional = true } rust-netrc = "0.1" url = "2.5" + +[features] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] diff --git a/oma-console/Cargo.toml b/oma-console/Cargo.toml index 5a6848964..a734f4bb1 100644 --- a/oma-console/Cargo.toml +++ b/oma-console/Cargo.toml @@ -8,10 +8,12 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chrono = { version = "0.4.38", optional = true } console = { version = "0.16", optional = true } indicatif = { version = "0.18", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } tracing = { version = "0.1", optional = true } -tracing-subscriber = { version = "0.3", optional = true } +tracing-subscriber = { version = "0.3", optional = true } ratatui = { version = "0.29", optional = true } # https://github.com/async-rs/async-std/issues/1055 # https://github.com/tokio-rs/tokio/issues/5535 @@ -21,7 +23,9 @@ textwrap = { version = "0.16", optional = true } aho-corasick = { version = "1.1.3", optional = true } [features] -print = ["dep:tracing", "dep:tracing-subscriber", "dep:textwrap", "dep:console", "dep:termbg"] +tracing = ["dep:tracing", "dep:tracing-subscriber"] +print = ["dep:textwrap", "dep:console", "dep:termbg", "dep:chrono"] pager = ["dep:ratatui", "dep:ansi-to-tui", "dep:console", "dep:aho-corasick"] progress_bar_style = ["dep:indicatif"] +spdlog-rs = ["dep:spdlog-rs"] default = ["print", "pager", "progress_bar_style"] diff --git a/oma-console/examples/msg.rs b/oma-console/examples/msg.rs index 572841c9c..a5969d7f0 100644 --- a/oma-console/examples/msg.rs +++ b/oma-console/examples/msg.rs @@ -1,6 +1,12 @@ +#[cfg(feature = "spdlog-rs")] +use oma_console::OmaFormatter; + +#[cfg(not(feature = "spdlog-rs"))] use oma_console::OmaLayer; +#[cfg(not(feature = "spdlog-rs"))] use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt}; +#[cfg(not(feature = "spdlog-rs"))] fn main() { tracing_subscriber::registry().with(OmaLayer::new()).init(); tracing::info!("Welcome"); @@ -9,3 +15,18 @@ fn main() { tracing::warn!("Thank you"); tracing::error!("and you?"); } + +#[cfg(feature = "spdlog-rs")] +fn main() { + spdlog::default_logger() + .sinks() + .iter() + .for_each(|s| s.set_formatter(Box::new(OmaFormatter::default()))); + spdlog::default_logger().set_level_filter(spdlog::LevelFilter::All); + + spdlog::info!("Welcome"); + spdlog::debug!("Hello"); + spdlog::info!("I'am fine"); + spdlog::warn!("Thank you"); + spdlog::error!("and you?"); +} diff --git a/oma-console/src/lib.rs b/oma-console/src/lib.rs index e0f3a6c10..2adfd6e71 100644 --- a/oma-console/src/lib.rs +++ b/oma-console/src/lib.rs @@ -29,9 +29,12 @@ pub mod writer; #[cfg(feature = "print")] pub mod print; -#[cfg(feature = "print")] +#[cfg(not(all(feature = "print", feature = "spdlog-rs")))] pub use print::OmaLayer; +#[cfg(all(feature = "print", feature = "spdlog-rs"))] +pub use print::OmaFormatter; + #[cfg(feature = "print")] pub use console; diff --git a/oma-console/src/pager.rs b/oma-console/src/pager.rs index 446f0bf3e..a6ece2592 100644 --- a/oma-console/src/pager.rs +++ b/oma-console/src/pager.rs @@ -22,7 +22,10 @@ use ratatui::{ }, widgets::Borders, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; use termbg::Theme; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; use crate::{print::OmaColorFormat, writer::Writer}; diff --git a/oma-console/src/print.rs b/oma-console/src/print.rs index a8db3a53d..90e3e6af0 100644 --- a/oma-console/src/print.rs +++ b/oma-console/src/print.rs @@ -1,12 +1,26 @@ -use std::{borrow::Cow, collections::BTreeMap, time::Duration}; +#[cfg(not(feature = "spdlog-rs"))] +use std::collections::BTreeMap; +#[cfg(feature = "spdlog-rs")] +use std::fmt::{self, Write}; +use std::{borrow::Cow, time::Duration}; + +#[cfg(feature = "spdlog-rs")] +use chrono::{DateTime, SecondsFormat, Utc}; use console::{Color, StyledObject, style}; +#[cfg(feature = "spdlog-rs")] +use spdlog::{Level, debug, formatter::Formatter}; use termbg::Theme; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{Level, debug, field::Field}; +#[cfg(not(feature = "spdlog-rs"))] use tracing_subscriber::Layer; pub use termbg; +#[cfg(feature = "spdlog-rs")] +use crate::writer::gen_prefix; +#[cfg(not(feature = "spdlog-rs"))] use crate::writer::{Writeln, Writer}; #[derive(Clone)] @@ -131,6 +145,141 @@ fn term_color(input: D, color: Action) -> StyledObject { Action::PendingBg => style(input).bg(Color::Blue).bold(), } } + +#[cfg(feature = "spdlog-rs")] +#[derive(Clone)] +pub struct OmaFormatter { + with_ansi: bool, + with_time: bool, + with_file: bool, + prefix_len: u16, +} + +#[cfg(feature = "spdlog-rs")] +impl Default for OmaFormatter { + fn default() -> Self { + Self { + with_ansi: true, + with_file: false, + with_time: false, + prefix_len: 10, + } + } +} + +#[cfg(feature = "spdlog-rs")] +impl OmaFormatter { + pub fn new() -> Self { + OmaFormatter::default() + } + + /// Display with ANSI colors + /// + /// Set to false to disable ANSI color sequences. + pub fn with_ansi(mut self, with_ansi: bool) -> Self { + self.with_ansi = with_ansi; + self + } + + pub fn with_file(mut self, with_file: bool) -> Self { + self.with_file = with_file; + self + } + + pub fn with_time(mut self, with_time: bool) -> Self { + self.with_time = with_time; + self + } + + fn format_impl( + &self, + record: &spdlog::Record, + dest: &mut spdlog::StringBuf, + _: &mut spdlog::formatter::FormatterContext, + ) -> fmt::Result { + let level = record.level(); + + let prefix = if self.with_ansi { + Cow::Owned(match level { + Level::Debug => console::style("DEBUG").dim().to_string(), + Level::Info => console::style("INFO").blue().bold().to_string(), + Level::Warn => console::style("WARNING").yellow().bold().to_string(), + Level::Error => console::style("ERROR").red().bold().to_string(), + Level::Trace => console::style("TRACE").dim().to_string(), + Level::Critical => console::style("CRITICAL").red().bright().bold().to_string(), + }) + } else { + Cow::Borrowed(match level { + Level::Debug => "DEBUG", + Level::Info => "INFO", + Level::Warn => "WARNING", + Level::Error => "ERROR", + Level::Trace => "TRACE", + Level::Critical => "CRITICAL", + }) + }; + + if self.with_time { + let time = { + let time = DateTime::::from(record.time()) + .to_rfc3339_opts(SecondsFormat::Millis, true); + + if self.with_ansi { + console::style(time).dim().to_string() + } else { + time + } + }; + + dest.write_str(&time)?; + dest.write_char(' ')?; + }; + + dest.write_str(&gen_prefix(&prefix, self.prefix_len))?; + dest.write_char(' ')?; + + if self.with_file { + let loc = record.source_location(); + + if let Some(loc) = loc { + let loc = format!("{}: {}:", loc.module_path(), loc.file()); + + let loc = if self.with_ansi { + console::style(loc).dim().to_string() + } else { + loc + }; + + dest.write_str(&loc)?; + dest.write_char(' ')?; + } + } + + if self.with_ansi { + dest.write_str(record.payload())?; + } else { + dest.write_str(&console::strip_ansi_codes(record.payload()))?; + } + + dest.write_char('\n')?; + + Ok(()) + } +} + +#[cfg(feature = "spdlog-rs")] +impl Formatter for OmaFormatter { + fn format( + &self, + record: &spdlog::Record, + dest: &mut spdlog::StringBuf, + ctx: &mut spdlog::formatter::FormatterContext, + ) -> spdlog::Result<()> { + self.format_impl(record, dest, ctx) + .map_err(|e| spdlog::Error::FormatRecord(e)) + } +} + /// OmaLayer /// `OmaLayer` is used for outputting oma-style logs to `tracing` /// @@ -147,6 +296,7 @@ fn term_color(input: D, color: Action) -> StyledObject { /// info!("My name is oma!"); /// ``` /// +#[cfg(not(feature = "spdlog-rs"))] pub struct OmaLayer { /// Display result with ansi with_ansi: bool, @@ -154,15 +304,18 @@ pub struct OmaLayer { writer: Writer, } +#[cfg(not(feature = "spdlog-rs"))] impl Default for OmaLayer { fn default() -> Self { Self { with_ansi: true, + #[cfg(not(feature = "spdlog-rs"))] writer: Writer::default(), } } } +#[cfg(not(feature = "spdlog-rs"))] impl OmaLayer { pub fn new() -> Self { OmaLayer::default() @@ -177,6 +330,7 @@ impl OmaLayer { } } +#[cfg(not(feature = "spdlog-rs"))] impl Layer for OmaLayer where S: tracing::Subscriber, @@ -236,8 +390,10 @@ where /// } /// } /// ``` +#[cfg(not(feature = "spdlog-rs"))] struct OmaRecorder<'a>(BTreeMap<&'a str, String>); +#[cfg(not(feature = "spdlog-rs"))] impl tracing::field::Visit for OmaRecorder<'_> { fn record_f64(&mut self, field: &Field, value: f64) { self.0.insert(field.name(), value.to_string()); diff --git a/oma-contents/Cargo.toml b/oma-contents/Cargo.toml index 4bdb8a60e..02c9dcd69 100644 --- a/oma-contents/Cargo.toml +++ b/oma-contents/Cargo.toml @@ -14,10 +14,13 @@ winnow = "0.7" flate2 = "1.0" rayon = "1.8" lzzzz = "2.0" -tracing = "0.1" +tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } which = "8" zstd = "0.13" memchr = "2" [features] aosc = [] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] diff --git a/oma-contents/src/parser.rs b/oma-contents/src/parser.rs index fce0d32cb..28703c8b9 100644 --- a/oma-contents/src/parser.rs +++ b/oma-contents/src/parser.rs @@ -3,7 +3,7 @@ use winnow::{ModalResult, Parser, combinator::separated, token::take_till}; use crate::OmaContentsError; /// Parse Contents file from input -pub fn parse_contetns(input: &str) -> Result)>, OmaContentsError> { +pub fn parse_contents(input: &str) -> Result)>, OmaContentsError> { input .lines() .enumerate() diff --git a/oma-contents/src/searcher.rs b/oma-contents/src/searcher.rs index 6e5ff90b9..ac6e3d98b 100644 --- a/oma-contents/src/searcher.rs +++ b/oma-contents/src/searcher.rs @@ -14,6 +14,9 @@ use flate2::bufread::GzDecoder; use lzzzz::lz4f::BufReadDecompressor; use memchr::memmem; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; use zstd::Decoder; diff --git a/oma-fetch/Cargo.toml b/oma-fetch/Cargo.toml index 4f181a835..2f810932b 100644 --- a/oma-fetch/Cargo.toml +++ b/oma-fetch/Cargo.toml @@ -20,7 +20,8 @@ async-compression = { version = "=0.4.27", features = ["gzip", "xz", "futures-io # even with older liblzma (Ubuntu 22.04 uses 5.2.x). Be mindful, however, that # async-compression depends on a different liblzma-rs than what is specified here. liblzma = { version = "0", features = ["uncheck_liblzma_version"] } -tracing = "0.1" +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +tracing = { version = "0.1", optional = true } tokio-util = { version = "0.7", features = ["compat"] } md-5 = "0.10.6" bon = "3" @@ -33,4 +34,6 @@ flume = "0.11.1" [features] rustls = ["reqwest/rustls-tls"] native-tls = ["reqwest/native-tls"] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] default = ["rustls"] diff --git a/oma-fetch/src/download.rs b/oma-fetch/src/download.rs index cdf920d6a..91f1d2143 100644 --- a/oma-fetch/src/download.rs +++ b/oma-fetch/src/download.rs @@ -22,7 +22,10 @@ use tokio::{ time::timeout, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, trace}; use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, trace}; use crate::{DownloadEntry, DownloadSourceType}; diff --git a/oma-fetch/src/lib.rs b/oma-fetch/src/lib.rs index cfbec94ef..fc0d9d2af 100644 --- a/oma-fetch/src/lib.rs +++ b/oma-fetch/src/lib.rs @@ -6,6 +6,9 @@ use download::{BuilderError, SingleDownloader, SuccessSummary}; use futures::StreamExt; use reqwest::{Client, Method, RequestBuilder, Response}; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; pub mod checksum; diff --git a/oma-history/Cargo.toml b/oma-history/Cargo.toml index a78846273..e167a8110 100644 --- a/oma-history/Cargo.toml +++ b/oma-history/Cargo.toml @@ -12,8 +12,13 @@ oma-pm-operation-type = { version = "0.9", path = "../oma-pm-operation-type" } rusqlite = { version = "0.37", features = ["bundled"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tracing = "0.1" +tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } thiserror = "2" [dev-dependencies] chrono = "0.4" + +[features] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] diff --git a/oma-history/src/lib.rs b/oma-history/src/lib.rs index bb6d48779..3d184bd05 100644 --- a/oma-history/src/lib.rs +++ b/oma-history/src/lib.rs @@ -11,7 +11,10 @@ use migrations::create_and_maybe_migration_from_oma_db_v2; use oma_pm_operation_type::{InstallOperation, OmaOperation, RemoveTag}; use rusqlite::{Connection, Error, Result}; use serde::Deserialize; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; use thiserror::Error; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; pub struct HistoryEntryInner { diff --git a/oma-history/src/migrations.rs b/oma-history/src/migrations.rs index f58b6130f..bea6fcb09 100644 --- a/oma-history/src/migrations.rs +++ b/oma-history/src/migrations.rs @@ -2,6 +2,9 @@ use oma_pm_operation_type::{InstallOperation, RemoveTag}; use rusqlite::Connection; use serde::Deserialize; use serde_json::Value; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, info, warn}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, info, warn}; use crate::{ diff --git a/oma-mirror/Cargo.toml b/oma-mirror/Cargo.toml index 634f9fb6b..6ccc9e915 100644 --- a/oma-mirror/Cargo.toml +++ b/oma-mirror/Cargo.toml @@ -11,6 +11,11 @@ serde_json = "1.0" snafu = "0.8.5" indexmap = { version = "2.6", features = ["serde"] } ahash = "0.8.11" -tracing = "0.1" +tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } once_cell = "1.19" toml = { version = "0.9", features = ["preserve_order"] } + +[features] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] diff --git a/oma-mirror/src/lib.rs b/oma-mirror/src/lib.rs index a35cf94af..ab74cf608 100644 --- a/oma-mirror/src/lib.rs +++ b/oma-mirror/src/lib.rs @@ -11,6 +11,9 @@ use indexmap::{IndexMap, indexmap}; use once_cell::sync::OnceCell; use serde::{Deserialize, Serialize}; use snafu::{ResultExt, Snafu}; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; use crate::parser::{ diff --git a/oma-pm/Cargo.toml b/oma-pm/Cargo.toml index 9b8f46690..8f494db59 100644 --- a/oma-pm/Cargo.toml +++ b/oma-pm/Cargo.toml @@ -20,11 +20,12 @@ oma-utils = { version = "^0.12.0", path = "../oma-utils", features = [ ] } oma-fetch = { version = "^0.34.0", path = "../oma-fetch" } tokio = { version = "1.15", default-features = false, features = [ - "fs", - "rt-multi-thread", + "fs", + "rt-multi-thread", ] } fs4 = "0.13" -tracing = "0.1" +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +tracing = { version = "0.1", optional = true } oma-pm-operation-type = { version = "0.9", path = "../oma-pm-operation-type" } zbus = { version = "5.1", features = ["tokio"] } cxx = "1.0.121" @@ -44,3 +45,5 @@ flume = "0.11" [features] aosc = ["dep:sysinfo"] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] diff --git a/oma-pm/src/apt.rs b/oma-pm/src/apt.rs index 33ca21d0c..05b560aac 100644 --- a/oma-pm/src/apt.rs +++ b/oma-pm/src/apt.rs @@ -27,9 +27,14 @@ use oma_fetch::{Event, Summary, checksum::ChecksumError, reqwest::Client}; use oma_utils::{dpkg::DpkgError, human_bytes::HumanBytes, is_termux}; pub use oma_apt::config::Config as AptConfig; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, error}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, error}; -#[cfg(feature = "aosc")] +#[cfg(all(feature = "aosc", feature = "spdlog-rs"))] +use spdlog::warn; +#[cfg(all(feature = "aosc", not(feature = "spdlog-rs")))] use tracing::warn; pub use oma_pm_operation_type::*; diff --git a/oma-pm/src/commit.rs b/oma-pm/src/commit.rs index 3bb9f037d..7b8b19b2b 100644 --- a/oma-pm/src/commit.rs +++ b/oma-pm/src/commit.rs @@ -9,7 +9,10 @@ use oma_apt::{ }; use oma_fetch::{Event, Summary, reqwest::Client}; use oma_pm_operation_type::{InstallEntry, OmaOperation}; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; use std::io::Write; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; use crate::{ diff --git a/oma-pm/src/dbus.rs b/oma-pm/src/dbus.rs index 6c6dd83b3..c071f8c84 100644 --- a/oma-pm/src/dbus.rs +++ b/oma-pm/src/dbus.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; use zbus::{Connection, Result, interface, proxy}; diff --git a/oma-pm/src/download.rs b/oma-pm/src/download.rs index 6703098e0..a72af7359 100644 --- a/oma-pm/src/download.rs +++ b/oma-pm/src/download.rs @@ -6,6 +6,9 @@ use oma_fetch::{ }; use oma_pm_operation_type::InstallEntry; use oma_utils::url_no_escape::url_no_escape_times; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; use crate::{ diff --git a/oma-pm/src/matches.rs b/oma-pm/src/matches.rs index e4a66d702..320856441 100644 --- a/oma-pm/src/matches.rs +++ b/oma-pm/src/matches.rs @@ -14,6 +14,9 @@ use oma_utils::{ url_no_escape::url_no_escape, }; use once_cell::sync::OnceCell; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, info}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, info}; use crate::pkginfo::{OmaPackage, OmaPackageWithoutVersion, PtrIsNone}; diff --git a/oma-pm/src/utils.rs b/oma-pm/src/utils.rs index ce8ba11b6..2c17f6293 100644 --- a/oma-pm/src/utils.rs +++ b/oma-pm/src/utils.rs @@ -1,4 +1,8 @@ +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, warn}; use std::{fs, io, path::Path}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{debug, warn}; #[cfg(feature = "aosc")] pub fn pkg_is_current_kernel( @@ -13,13 +17,13 @@ pub fn pkg_is_current_kernel( sysroot: &Path, ) -> bool { is_installed_pkg_contains_file(pkg_name, image_names, sysroot).unwrap_or_else(|e| { - tracing::warn!("Failed to get package {pkg_name} file list: {e}"); + warn!("Failed to get package {pkg_name} file list: {e}"); false }) } let image_name = image_name.get_or_init(get_kernel_image_filename); - tracing::debug!("image name = {image_name:?}"); + debug!("image name = {image_name:?}"); if let Some(image_name) = image_name { is_installed_pkg_contains_file_impl(pkg_name, &[image_name], sysroot) diff --git a/oma-refresh/Cargo.toml b/oma-refresh/Cargo.toml index 73081846d..a257d49b6 100644 --- a/oma-refresh/Cargo.toml +++ b/oma-refresh/Cargo.toml @@ -11,12 +11,17 @@ license = "GPL-3.0-or-later" oma-fetch = { version = "^0.34.0", path = "../oma-fetch", default-features = false } thiserror = "2" url = "2.3" -tokio = { version = "1.28", default-features = false, features = ["fs", "process", "macros"] } +tokio = { version = "1.28", default-features = false, features = [ + "fs", + "process", + "macros", +] } futures = "0.3" oma-apt-sources-lists = "0.9" chrono = { version = "0.4", features = ["unstable-locales"] } oma-topics = { version = "^0.25.0", path = "../oma-topics", optional = true, default-features = false } -tracing ="0.1" +tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } oma-repo-verify = { version = "^0.9.0", path = "../oma-repo-verify", default-features = false } ahash = "0.8.11" oma-apt = { version = "0.11", optional = true } @@ -41,10 +46,14 @@ rustls = ["oma-fetch/rustls", "oma-topics/rustls"] native-tls = ["oma-fetch/native-tls", "oma-topics/native-tls"] apt = ["dep:oma-apt"] blocking = ["tokio/rt", "tokio/rt-multi-thread"] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] default = ["aosc", "sequoia-nettle-backend", "rustls", "apt"] [dev-dependencies] -tokio = { version = "1.28", default-features = false, features = ["rt-multi-thread"] } +tokio = { version = "1.28", default-features = false, features = [ + "rt-multi-thread", +] } flume = "0.11.1" oma-utils = { version = "^0.12.0", path = "../oma-utils", features = ["dpkg"] } diff --git a/oma-refresh/src/config.rs b/oma-refresh/src/config.rs index b4fe349ae..1f8010e54 100644 --- a/oma-refresh/src/config.rs +++ b/oma-refresh/src/config.rs @@ -6,6 +6,9 @@ use aho_corasick::AhoCorasick; use oma_apt::config::{Config, ConfigTree}; use oma_fetch::CompressFile; use once_cell::sync::OnceCell; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; use crate::{db::RefreshError, inrelease::ChecksumItem}; diff --git a/oma-refresh/src/db.rs b/oma-refresh/src/db.rs index 59efab1c9..3c22e84ec 100644 --- a/oma-refresh/src/db.rs +++ b/oma-refresh/src/db.rs @@ -40,11 +40,15 @@ use oma_topics::TopicManager; use oma_fetch::reqwest::StatusCode; use oma_utils::is_termux; + +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, warn}; use sysinfo::{Pid, System}; use tokio::{ fs::{self}, task::spawn_blocking, }; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, warn}; use crate::sourceslist::{MirrorSource, MirrorSources, scan_sources_list_from_paths}; @@ -392,7 +396,6 @@ impl<'a> OmaRefresh<'a> { #[cfg(feature = "apt")] async fn run_success_post_invoke(&self) { use tokio::process::Command; - use tracing::warn; let cmds = self .apt_config diff --git a/oma-refresh/src/inrelease.rs b/oma-refresh/src/inrelease.rs index 2578fbbe8..f3ec3641a 100644 --- a/oma-refresh/src/inrelease.rs +++ b/oma-refresh/src/inrelease.rs @@ -3,6 +3,8 @@ use deb822_fast::{FromDeb822, FromDeb822Paragraph, Paragraph}; use oma_apt_sources_lists::Signature; use oma_repo_verify::verify_release_by_sysroot; use once_cell::sync::OnceCell; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, trace}; use std::{ borrow::Cow, fs, @@ -12,6 +14,7 @@ use std::{ str::FromStr, }; use thiserror::Error; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, trace}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/oma-refresh/src/sourceslist.rs b/oma-refresh/src/sourceslist.rs index 7c063346f..a432e9ba7 100644 --- a/oma-refresh/src/sourceslist.rs +++ b/oma-refresh/src/sourceslist.rs @@ -17,11 +17,14 @@ use oma_fetch::{ send_request, }; use once_cell::sync::OnceCell; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, warn}; use tokio::{ fs::{self, File}, io::AsyncWriteExt, }; -use tracing::debug; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{debug, warn}; use url::Url; use crate::{ @@ -81,8 +84,6 @@ pub(crate) async fn scan_sources_lists_paths_from_sysroot( #[cfg(feature = "apt")] pub fn ignores(config: &oma_apt::config::Config) -> Vec { - use tracing::warn; - config.find_vector("Dir::Ignore-Files-Silently") .iter() .filter_map(|re| Regex::new(re) diff --git a/oma-repo-verify/Cargo.toml b/oma-repo-verify/Cargo.toml index 576a695d2..2b7eb58fb 100644 --- a/oma-repo-verify/Cargo.toml +++ b/oma-repo-verify/Cargo.toml @@ -9,11 +9,14 @@ license = "MIT" anyhow = "1" thiserror = "2" sequoia-openpgp = { version = "2", default-features = false } -tracing = "0.1" +spdlog-rs = { git = 'https://github.com/SpriteOvO/spdlog-rs.git', branch = "sink-decouple", optional = true } +tracing = { version = "0.1", optional = true } oma-apt-sources-lists = "0.9" sequoia-policy-config = "0.8" [features] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] sequoia-openssl-backend = ["sequoia-openpgp/crypto-openssl"] sequoia-nettle-backend = ["sequoia-openpgp/crypto-nettle"] default = ["sequoia-nettle-backend"] diff --git a/oma-repo-verify/src/lib.rs b/oma-repo-verify/src/lib.rs index 6568c6043..ae11af5ce 100644 --- a/oma-repo-verify/src/lib.rs +++ b/oma-repo-verify/src/lib.rs @@ -18,6 +18,9 @@ use sequoia_openpgp::{ policy::StandardPolicy, }; use sequoia_policy_config::ConfiguredStandardPolicy; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; #[derive(Debug)] diff --git a/oma-topics/Cargo.toml b/oma-topics/Cargo.toml index 68e352e35..5923b7aa2 100644 --- a/oma-topics/Cargo.toml +++ b/oma-topics/Cargo.toml @@ -11,10 +11,15 @@ license = "MIT" reqwest = { version = "0.12", features = ["json"], default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tokio = { version = "1.28", default-features = false, features = ["fs", "rt", "rt-multi-thread"] } +tokio = { version = "1.28", default-features = false, features = [ + "fs", + "rt", + "rt-multi-thread", +] } thiserror = "2.0" futures = "0.3" -tracing = "0.1" +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +tracing = { version = "0.1", optional = true } url = "2.5" oma-mirror = { version = "0.7.0", path = "../oma-mirror" } ahash = "0.8.11" @@ -22,9 +27,14 @@ ahash = "0.8.11" [dev-dependencies] oma-inquire = "0.3" oma-console = { path = "../oma-console" } -tokio = { version = "1.28", default-features = false, features = ["macros", "rt-multi-thread"] } +tokio = { version = "1.28", default-features = false, features = [ + "macros", + "rt-multi-thread", +] } [features] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] rustls = ["reqwest/rustls-tls"] native-tls = ["reqwest/native-tls"] default = ["rustls"] diff --git a/oma-topics/src/lib.rs b/oma-topics/src/lib.rs index 79a70d4a1..ff52bf155 100644 --- a/oma-topics/src/lib.rs +++ b/oma-topics/src/lib.rs @@ -9,7 +9,10 @@ use futures::future::try_join_all; use oma_mirror::{MirrorError, MirrorManager, parser::MirrorsConfigTemplate, write_sources_inner}; use reqwest::Client; use serde::{Deserialize, Serialize, de::DeserializeOwned}; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, warn}; use tokio::fs; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, warn}; use url::Url; diff --git a/oma-tum/Cargo.toml b/oma-tum/Cargo.toml index e70d87ff5..d9a097a2e 100644 --- a/oma-tum/Cargo.toml +++ b/oma-tum/Cargo.toml @@ -11,9 +11,14 @@ snafu = "0.8.6" serde = { version = "1", features = ["derive"] } serde_json = "1" ahash = "0.8.12" -tracing = "0.1" +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +tracing = { version = "0.1", optional = true } logos = "0.15" debversion = "0.4.5" [dev-dependencies] tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } + +[features] +spdlog-rs = ["dep:spdlog-rs"] +tracing = ["dep:tracing"] diff --git a/oma-tum/src/lib.rs b/oma-tum/src/lib.rs index bd13e35e7..449a9bafe 100644 --- a/oma-tum/src/lib.rs +++ b/oma-tum/src/lib.rs @@ -10,6 +10,9 @@ use debversion::Version; use oma_pm_operation_type::{InstallOperation, OmaOperation}; use serde::Deserialize; use snafu::{ResultExt, Snafu, Whatever}; +#[cfg(feature = "spdlog-rs")] +use spdlog::warn; +#[cfg(not(feature = "spdlog-rs"))] use tracing::warn; use crate::parser::{VersionToken, parse_version_expr}; diff --git a/oma-utils/Cargo.toml b/oma-utils/Cargo.toml index ec00c5c6d..63b7b75ca 100644 --- a/oma-utils/Cargo.toml +++ b/oma-utils/Cargo.toml @@ -13,7 +13,8 @@ number_prefix = { version = "0.4", optional = true } os-release = "0.1" zbus = { version = "5.1", optional = true } url-escape = { version = "0.1", optional = true } -tracing = "0.1" +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +tracing = { version = "0.1", optional = true } logind-zbus = "5.1" [features] diff --git a/oma-utils/src/dbus/mod.rs b/oma-utils/src/dbus/mod.rs index a72e3f481..0b341baca 100644 --- a/oma-utils/src/dbus/mod.rs +++ b/oma-utils/src/dbus/mod.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use logind_zbus::session::SessionProxy; -use tracing::debug; +use spdlog::debug; use zbus::{Result as zResult, proxy, zvariant::OwnedFd}; pub use zbus::Connection; diff --git a/oma-utils/src/dpkg/mod.rs b/oma-utils/src/dpkg/mod.rs index aef443b4f..b7b43df9e 100644 --- a/oma-utils/src/dpkg/mod.rs +++ b/oma-utils/src/dpkg/mod.rs @@ -4,6 +4,9 @@ use std::{ process::{Command, Stdio}, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; #[derive(Debug, thiserror::Error)] diff --git a/src/config.rs b/src/config.rs index 642401fb1..cc7829365 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,9 @@ -use crate::{error, fl}; +use crate::fl; use serde::{Deserialize, Serialize}; -use tracing::warn; +#[cfg(feature = "spdlog-rs")] +use spdlog::{error, warn}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{error, warn}; #[cfg(feature = "aosc")] const DEFAULT_CONFIG: &str = include_str!("../data/config/oma.toml"); diff --git a/src/error.rs b/src/error.rs index c77645a53..2d05c58b7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,6 +29,9 @@ use oma_utils::dpkg::DpkgError; #[cfg(feature = "aosc")] use oma_topics::OmaTopicsError; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, error, info}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, error, info}; use crate::subcommand::utils::LockError; diff --git a/src/main.rs b/src/main.rs index 14dd51c89..6796bc6e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,8 @@ use std::io::{self, IsTerminal, stderr, stdin}; use std::path::{Path, PathBuf}; use std::process::{Command, exit}; +#[cfg(feature = "spdlog-rs")] +use std::sync::Arc; use std::sync::{LazyLock, OnceLock}; use std::thread; use std::time::{Duration, SystemTime, UNIX_EPOCH}; @@ -29,6 +31,9 @@ use clap_i18n_richformatter::{ClapI18nRichFormatter, init_clap_rich_formatter_lo use error::OutputError; use i18n_embed::{DesktopLanguageRequester, Localizer}; use lang::LANGUAGE_LOADER; +#[cfg(feature = "spdlog-rs")] +use oma_console::OmaFormatter; +#[cfg(not(feature = "spdlog-rs"))] use oma_console::OmaLayer; use oma_console::print::{OmaColorFormat, termbg}; use oma_console::writer::{MessageType, Writer, writeln_inner}; @@ -37,13 +42,23 @@ use oma_utils::dbus::{create_dbus_connection, get_another_oma_status}; use oma_utils::{OsRelease, is_termux}; use reqwest::Client; use rustix::stdio::stdout; +// FIXME: `spdlog::error` is conflict with `mod error` +#[cfg(feature = "spdlog-rs")] +use spdlog::{ + Level, LevelFilter, Logger, debug, default_logger, error as error2, info, set_default_logger, + sink::{AsyncPoolSink, RotatingFileSink, RotationPolicy, StdStreamSink}, + warn, +}; use subcommand::utils::{LockError, is_terminal}; use tokio::runtime::Runtime; -use tracing::{debug, error, info, warn}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{debug, error as error2, info, warn}; +#[cfg(not(feature = "spdlog-rs"))] use tracing_appender::non_blocking::WorkerGuard; -use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; -use tracing_subscriber::{EnvFilter, Layer, fmt}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing_subscriber::{ + EnvFilter, Layer, fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, +}; use tui::Tui; use utils::{is_root, is_ssh_from_loginctl}; @@ -298,6 +313,84 @@ macro_rules! init_logger_inner { ($context:ident) => {{ $context.init() }}; } +#[cfg(feature = "spdlog-rs")] +fn init_logger( + oma: &OhManagerAilurus, + config: &Config, +) -> (Option>, anyhow::Result) { + let debug = oma.global.debug; + let dry_run = oma.global.dry_run; + + let log_dir = if is_root() { + PathBuf::from("/var/log/oma") + } else { + dirs::state_dir() + .expect("Failed to get state dir") + .join("oma") + }; + + let log_file = create_log_file(&log_dir); + + let (level_filter, formatter) = if !debug && !dry_run { + let level_filter = LevelFilter::MoreSevereEqual(Level::Info); + + let formatter = OmaFormatter::new().with_ansi(enable_ansi(oma)); + + (level_filter, formatter) + } else { + let level_filter = LevelFilter::MoreSevereEqual(Level::Debug); + + let formatter = OmaFormatter::new() + .with_ansi(enable_ansi(oma)) + .with_file(true) + .with_time(true); + + (level_filter, formatter) + }; + + let rotating_sink = if let Ok(log_file) = &log_file { + Some( + AsyncPoolSink::builder() + .sink(Arc::new( + RotatingFileSink::builder() + .base_path(&log_file) + .formatter(formatter.clone()) + .rotation_policy(RotationPolicy::Hourly) + .build() + .unwrap(), + )) + .overflow_policy(spdlog::sink::OverflowPolicy::DropIncoming) + .build() + .unwrap(), + ) + } else { + None + }; + + let stream_sink = StdStreamSink::builder() + .formatter(formatter) + .stdout() + .build() + .unwrap(); + + let mut logger_builder = Logger::builder(); + + logger_builder + .level_filter(level_filter) + .sink(Arc::new(stream_sink)); + + if let Some(rotating_sink) = rotating_sink { + logger_builder.sink(Arc::new(rotating_sink)); + } + + let logger = logger_builder.build().unwrap(); + + set_default_logger(Arc::new(logger)); + + (Some(default_logger()), log_file) +} + +#[cfg(not(feature = "spdlog-rs"))] fn init_logger( oma: &OhManagerAilurus, config: &Config, @@ -452,7 +545,7 @@ fn try_main( if !plugin.is_file() { plugin = plugin_fallback; if !plugin.is_file() { - error!("{}", fl!("custom-command-unknown", subcmd = subcommand)); + error2!("{}", fl!("custom-command-unknown", subcmd = subcommand)); return Ok(1); } } @@ -465,7 +558,7 @@ fn try_main( let status = process.status().unwrap().code().unwrap(); if status != 0 { - error!("{}", fl!("custom-command-applet-exception", s = status)); + error2!("{}", fl!("custom-command-applet-exception", s = status)); } Ok(status) @@ -557,7 +650,7 @@ fn color_formatter() -> &'static OmaColorFormat { fn display_error_and_can_unlock(e: OutputError) -> io::Result { let mut unlock = true; if !e.description.is_empty() { - error!("{e}"); + error2!("{e}"); let cause = Chain::new(&e).skip(1).collect::>(); let last_cause = cause.last(); @@ -604,7 +697,7 @@ fn display_error_and_can_unlock(e: OutputError) -> io::Result { unlock = false; if let Err(e) = find_another_oma() { debug!("{e}"); - error!("{}", fl!("failed-to-lock-oma")); + error2!("{}", fl!("failed-to-lock-oma")); } } } @@ -627,7 +720,7 @@ async fn find_another_oma_inner() -> Result<(), OutputError> { pkg => fl!("status-package", pkg = pkg), }; - error!("{}", fl!("another-oma-is-running", s = status)); + error2!("{}", fl!("another-oma-is-running", s = status)); Ok(()) } @@ -704,3 +797,6 @@ fn single_handler() { std::process::exit(130); } + +#[cfg(all(feature = "spdlog-rs", feature = "tracing"))] +compile_error!("feature spdlog-rs and tracing should not be enabled at the same time"); diff --git a/src/path_completions.rs b/src/path_completions.rs index 5b37f1a71..babc73615 100644 --- a/src/path_completions.rs +++ b/src/path_completions.rs @@ -6,6 +6,9 @@ use clap_complete::{CompletionCandidate, engine::ValueCompleter}; use clap_lex::OsStrExt; use dirs::home_dir; use rustix::path::Arg; +#[cfg(feature = "spdlog-rs")] +use spdlog::debug; +#[cfg(not(feature = "spdlog-rs"))] use tracing::debug; /// Complete a value as a [`std::path::Path`] diff --git a/src/pb.rs b/src/pb.rs index f925604ca..a8bec2db0 100644 --- a/src/pb.rs +++ b/src/pb.rs @@ -19,6 +19,9 @@ use crate::{WRITER, error::Chain, fl, install_progress::osc94_progress, msg, uti use crate::{color_formatter, error::OutputError}; use oma_refresh::db::Event as RefreshEvent; use oma_utils::human_bytes::HumanBytes; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, error, info, warn}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, error, info, warn}; pub trait RenderPackagesDownloadProgress { @@ -297,7 +300,7 @@ impl OmaMultiProgressBar { self.info(&fl!("can-not-get-source-next-url")); } Event::DownloadDone { index: _, msg } => { - tracing::debug!("Downloaded {msg}"); + debug!("Downloaded {msg}"); } Event::AllDone => { if let Some(gpb) = &self.pb_map.get(&0) { diff --git a/src/subcommand/clean.rs b/src/subcommand/clean.rs index 5b843fe77..3e7b6ba65 100644 --- a/src/subcommand/clean.rs +++ b/src/subcommand/clean.rs @@ -3,13 +3,16 @@ use std::io::ErrorKind; use std::path::{Path, PathBuf}; use crate::subcommand::utils::create_progress_spinner; +use crate::success; use crate::{config::Config, fl}; -use crate::{error, success}; use clap::Args; use fs_extra::dir::get_size; use oma_console::indicatif::HumanBytes; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; -use tracing::{debug, info}; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, error, info}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{debug, error, info}; use crate::{error::OutputError, utils::root}; diff --git a/src/subcommand/command_not_found.rs b/src/subcommand/command_not_found.rs index f5ab92ddb..ece45ab78 100644 --- a/src/subcommand/command_not_found.rs +++ b/src/subcommand/command_not_found.rs @@ -7,6 +7,9 @@ use oma_console::print::Action; use oma_contents::OmaContentsError; use oma_contents::searcher::{Mode, search}; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; +#[cfg(feature = "spdlog-rs")] +use spdlog::error; +#[cfg(not(feature = "spdlog-rs"))] use tracing::error; use crate::config::Config; diff --git a/src/subcommand/download.rs b/src/subcommand/download.rs index 7d5f963c3..006465fc2 100644 --- a/src/subcommand/download.rs +++ b/src/subcommand/download.rs @@ -6,6 +6,9 @@ use clap_complete::ArgValueCompleter; use flume::unbounded; use oma_pm::apt::{AptConfig, DownloadConfig, OmaApt, OmaAptArgs}; use oma_pm::matches::PackagesMatcher; +#[cfg(feature = "spdlog-rs")] +use spdlog::error; +#[cfg(not(feature = "spdlog-rs"))] use tracing::error; use crate::config::Config; diff --git a/src/subcommand/history.rs b/src/subcommand/history.rs index 10963f02d..f8bf43d9b 100644 --- a/src/subcommand/history.rs +++ b/src/subcommand/history.rs @@ -9,6 +9,9 @@ use oma_pm::matches::{GetArchMethod, PackagesMatcher}; use oma_pm::oma_apt::PackageSort; use oma_pm::pkginfo::PtrIsNone; use oma_pm::{apt::OmaApt, pkginfo::OmaPackage}; +#[cfg(feature = "spdlog-rs")] +use spdlog::warn; +#[cfg(not(feature = "spdlog-rs"))] use tracing::warn; use std::path::{Path, PathBuf}; @@ -315,7 +318,6 @@ impl CliExecuter for Undo { if code == 0 && (!opt_in.is_empty() || !opt_out.is_empty()) { use crate::RT; use crate::fl; - use tracing::warn; let arch = oma_utils::dpkg::dpkg_arch(&sysroot)?; let mut tm = oma_topics::TopicManager::new_blocking( diff --git a/src/subcommand/install.rs b/src/subcommand/install.rs index 3a694b3bf..6f4f63402 100644 --- a/src/subcommand/install.rs +++ b/src/subcommand/install.rs @@ -7,8 +7,10 @@ use oma_pm::apt::OmaApt; use oma_pm::apt::OmaAptArgs; use oma_pm::matches::GetArchMethod; use oma_pm::matches::PackagesMatcher; -use tracing::info; -use tracing::warn; +#[cfg(feature = "spdlog-rs")] +use spdlog::{info, warn}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{info, warn}; use crate::HTTP_CLIENT; use crate::args::ARG_HELP_HEADING; diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index b17e3cc15..64dc69cb3 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -7,6 +7,9 @@ use oma_pm::{ apt::{AptConfig, OmaApt, OmaAptArgs}, oma_apt::{PackageSort, PkgCurrentState, PkgSelectedState}, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::info; +#[cfg(not(feature = "spdlog-rs"))] use tracing::info; use crate::{NOT_DISPLAY_ABORT, fl, utils::pkgnames_completions}; diff --git a/src/subcommand/mark.rs b/src/subcommand/mark.rs index 96e7e8c1e..862f2d6bb 100644 --- a/src/subcommand/mark.rs +++ b/src/subcommand/mark.rs @@ -7,6 +7,9 @@ use oma_pm::{ apt::{AptConfig, OmaApt, OmaAptArgs}, matches::{GetArchMethod, PackagesMatcher}, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::info; +#[cfg(not(feature = "spdlog-rs"))] use tracing::info; use crate::{ diff --git a/src/subcommand/mirror.rs b/src/subcommand/mirror.rs index 4f0649aff..5acaa90fc 100644 --- a/src/subcommand/mirror.rs +++ b/src/subcommand/mirror.rs @@ -28,9 +28,11 @@ use oma_utils::dpkg::dpkg_arch; use reqwest::blocking; use sha2::Digest; use sha2::Sha256; +#[cfg(feature = "spdlog-rs")] +use spdlog::{error, info, warn}; use tabled::Tabled; -use tracing::warn; -use tracing::{error, info}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{error, info, warn}; use crate::APP_USER_AGENT; use crate::HTTP_CLIENT; diff --git a/src/subcommand/refresh.rs b/src/subcommand/refresh.rs index b9a609d7d..4a40159a1 100644 --- a/src/subcommand/refresh.rs +++ b/src/subcommand/refresh.rs @@ -2,6 +2,9 @@ use std::path::PathBuf; use clap::Args; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; +#[cfg(feature = "spdlog-rs")] +use spdlog::info; +#[cfg(not(feature = "spdlog-rs"))] use tracing::info; use crate::config::Config; diff --git a/src/subcommand/remove.rs b/src/subcommand/remove.rs index b8d4e0700..1b31d9ec1 100644 --- a/src/subcommand/remove.rs +++ b/src/subcommand/remove.rs @@ -8,6 +8,9 @@ use dialoguer::theme::ColorfulTheme; use dialoguer::{Confirm, Input}; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; use oma_pm::matches::{GetArchMethod, PackagesMatcher}; +#[cfg(feature = "spdlog-rs")] +use spdlog::{info, warn}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{info, warn}; use crate::config::Config; diff --git a/src/subcommand/show.rs b/src/subcommand/show.rs index 4b303930c..2ff847937 100644 --- a/src/subcommand/show.rs +++ b/src/subcommand/show.rs @@ -10,6 +10,9 @@ use oma_pm::{ oma_apt::records::RecordField, pkginfo::{AptSource, OmaPackage}, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::info; +#[cfg(not(feature = "spdlog-rs"))] use tracing::info; use crate::{config::Config, error::OutputError, utils::pkgnames_and_path_completions}; diff --git a/src/subcommand/size_analyzer.rs b/src/subcommand/size_analyzer.rs index c944c6dc9..5e997aec1 100644 --- a/src/subcommand/size_analyzer.rs +++ b/src/subcommand/size_analyzer.rs @@ -25,9 +25,12 @@ use ratatui::{ layout::{Direction, Layout}, prelude::Backend, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::info; use std::io::Write; use tabled::builder::Builder; use tabled::settings::{Alignment, Settings}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::info; use crate::utils::{dbus_check, is_root}; diff --git a/src/subcommand/topics.rs b/src/subcommand/topics.rs index 616ac7518..707435bd6 100644 --- a/src/subcommand/topics.rs +++ b/src/subcommand/topics.rs @@ -19,8 +19,11 @@ use oma_pm::{ }; use oma_utils::dpkg::dpkg_arch; use once_cell::sync::OnceCell; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, error, info, warn}; use sysinfo::System; use tokio::task::spawn_blocking; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, error, info, warn}; use crate::{ diff --git a/src/subcommand/upgrade.rs b/src/subcommand/upgrade.rs index 5593f2424..6451dbbee 100644 --- a/src/subcommand/upgrade.rs +++ b/src/subcommand/upgrade.rs @@ -2,7 +2,6 @@ use crate::subcommand::utils::CommitChanges; use crate::utils::pkgnames_and_path_completions; use clap_complete::ArgValueCompleter; use std::path::PathBuf; -use tracing::debug; use apt_auth_config::AuthConfig; use clap::Args; @@ -14,8 +13,10 @@ use oma_pm::apt::Upgrade as AptUpgrade; use oma_pm::matches::GetArchMethod; use oma_pm::matches::PackagesMatcher; -use tracing::info; -use tracing::warn; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, info, warn}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{debug, info, warn}; use crate::HTTP_CLIENT; use crate::config::Config; diff --git a/src/subcommand/utils.rs b/src/subcommand/utils.rs index 9895cd785..b6f6fd1f9 100644 --- a/src/subcommand/utils.rs +++ b/src/subcommand/utils.rs @@ -77,12 +77,12 @@ use oma_refresh::db::OmaRefresh; use oma_utils::dpkg::dpkg_arch; use reqwest::Client; use std::fmt::Display; -use tracing::debug; -use tracing::error; -use tracing::info; -use tracing::warn; use super::remove::ask_user_do_as_i_say; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, error, info, warn}; +#[cfg(not(feature = "spdlog-rs"))] +use tracing::{debug, error, info, warn}; pub(crate) fn handle_no_result(no_result: Vec<&str>, no_progress: bool) -> Result<(), OutputError> { if no_result.is_empty() { diff --git a/src/tui/mod.rs b/src/tui/mod.rs index d80c2742e..222d12d9b 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -13,6 +13,9 @@ use oma_utils::{ dbus::{InhibitTypeUnion, take_wake_lock}, is_termux, }; +#[cfg(feature = "spdlog-rs")] +use spdlog::info; +#[cfg(not(feature = "spdlog-rs"))] use tracing::info; use tui_inner::{Task, Tui as TuiInner}; diff --git a/src/utils.rs b/src/utils.rs index d2f75be3e..d32f59c17 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -31,6 +31,9 @@ use oma_utils::{ zbus::zvariant::OwnedFd, }; use rustix::process; +#[cfg(feature = "spdlog-rs")] +use spdlog::{debug, info, warn}; +#[cfg(not(feature = "spdlog-rs"))] use tracing::{debug, info, warn}; type Result = std::result::Result; @@ -249,7 +252,10 @@ macro_rules! msg { ($($arg:tt)+) => { use oma_console::writer::Writeln as _; let s = format!($($arg)+); + #[cfg(not(feature = "spdlog-rs"))] tracing::debug!("{s}"); + #[cfg(feature = "spdlog-rs")] + spdlog::debug!("{s}"); $crate::WRITER.writeln("", &s).ok(); }; } @@ -260,7 +266,10 @@ macro_rules! success { ($($arg:tt)+) => { use oma_console::writer::Writeln as _; let s = format!($($arg)+); + #[cfg(not(feature = "spdlog-rs"))] tracing::debug!("{s}"); + #[cfg(feature = "spdlog-rs")] + spdlog::debug!("{s}"); $crate::WRITER.writeln(&oma_console::console::style("SUCCESS").green().bold().to_string(), &s).ok(); }; } @@ -271,7 +280,10 @@ macro_rules! due_to { ($($arg:tt)+) => { use oma_console::writer::Writeln as _; let s = format!($($arg)+); + #[cfg(not(feature = "spdlog-rs"))] tracing::debug!("{s}"); + #[cfg(feature = "spdlog-rs")] + spdlog::debug!("{s}"); $crate::WRITER.writeln(&oma_console::console::style("DUE TO").yellow().bold().to_string(), &s).ok(); }; } From b3d89b51d4c31f260da7d188b54806b77744fa7f Mon Sep 17 00:00:00 2001 From: Neko Date: Fri, 19 Sep 2025 15:43:20 +0800 Subject: [PATCH 2/9] refactor: remove tracing codes --- Cargo.lock | 281 +++++++++------------------- Cargo.toml | 35 +--- apt-auth-config/Cargo.toml | 7 +- oma-console/Cargo.toml | 6 +- oma-console/examples/msg.rs | 17 -- oma-console/src/lib.rs | 5 +- oma-console/src/pager.rs | 3 - oma-console/src/print.rs | 180 ++---------------- oma-contents/Cargo.toml | 5 +- oma-contents/src/searcher.rs | 3 - oma-fetch/Cargo.toml | 5 +- oma-fetch/src/download.rs | 6 +- oma-fetch/src/lib.rs | 4 - oma-history/Cargo.toml | 7 +- oma-history/src/lib.rs | 3 - oma-history/src/migrations.rs | 3 - oma-mirror/Cargo.toml | 7 +- oma-mirror/src/lib.rs | 3 - oma-pm/Cargo.toml | 5 +- oma-pm/src/apt.rs | 10 +- oma-pm/src/commit.rs | 3 - oma-pm/src/dbus.rs | 3 - oma-pm/src/download.rs | 3 - oma-pm/src/matches.rs | 3 - oma-pm/src/utils.rs | 3 - oma-refresh/Cargo.toml | 15 +- oma-refresh/src/config.rs | 3 - oma-refresh/src/db.rs | 3 - oma-refresh/src/inrelease.rs | 3 - oma-refresh/src/sourceslist.rs | 3 - oma-repo-verify/Cargo.toml | 5 +- oma-repo-verify/src/lib.rs | 3 - oma-topics/Cargo.toml | 16 +- oma-topics/src/lib.rs | 3 - oma-tum/Cargo.toml | 10 +- oma-tum/examples/tum.rs | 3 - oma-tum/src/lib.rs | 3 - oma-utils/Cargo.toml | 3 +- oma-utils/src/dpkg/mod.rs | 3 - src/config.rs | 5 +- src/error.rs | 3 - src/main.rs | 151 +-------------- src/path_completions.rs | 3 - src/pb.rs | 3 - src/subcommand/clean.rs | 3 - src/subcommand/command_not_found.rs | 4 +- src/subcommand/download.rs | 3 - src/subcommand/history.rs | 3 - src/subcommand/install.rs | 3 - src/subcommand/list.rs | 3 - src/subcommand/mark.rs | 3 - src/subcommand/mirror.rs | 3 - src/subcommand/refresh.rs | 3 - src/subcommand/remove.rs | 3 - src/subcommand/show.rs | 3 - src/subcommand/size_analyzer.rs | 3 - src/subcommand/topics.rs | 3 - src/subcommand/tree.rs | 2 +- src/subcommand/upgrade.rs | 4 - src/subcommand/utils.rs | 3 - src/utils.rs | 12 -- 61 files changed, 139 insertions(+), 773 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a1c98b13..5333e4046 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,7 +69,7 @@ version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67555e1f1ece39d737e28c8a017721287753af3f93225e4a445b29ccb0f5912c" dependencies = [ - "nom", + "nom 7.1.3", "ratatui", "simdutf8", "smallvec", @@ -82,7 +82,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0a8acea8c2f1c60f0a92a8cd26bf96ca97db56f10bbcab238bbe0cceba659ee" dependencies = [ - "nom", + "nom 7.1.3", "vte", ] @@ -149,7 +149,6 @@ dependencies = [ "rust-netrc", "spdlog-rs", "thiserror 2.0.17", - "tracing", "url", ] @@ -297,7 +296,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -337,7 +336,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -354,7 +353,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -485,7 +484,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.106", + "syn", ] [[package]] @@ -577,7 +576,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.106", + "syn", ] [[package]] @@ -666,7 +665,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" dependencies = [ - "nom", + "nom 7.1.3", ] [[package]] @@ -760,10 +759,10 @@ version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1049,7 +1048,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.106", + "syn", ] [[package]] @@ -1063,7 +1062,7 @@ dependencies = [ "indexmap 2.11.4", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1082,7 +1081,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.106", + "syn", ] [[package]] @@ -1116,7 +1115,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.106", + "syn", ] [[package]] @@ -1130,7 +1129,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.106", + "syn", ] [[package]] @@ -1141,7 +1140,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ "darling_core 0.20.11", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1152,7 +1151,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" dependencies = [ "darling_core 0.21.3", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1163,7 +1162,7 @@ checksum = "86bf2d0fa4ce2457e94bd7efb15aeadc115297f04b660bd0da706729e0d91442" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1197,15 +1196,6 @@ dependencies = [ "num-bigint", ] -[[package]] -name = "deranged" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071" -dependencies = [ - "powerfmt", -] - [[package]] name = "dialoguer" version = "0.12.0" @@ -1285,7 +1275,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1330,7 +1320,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1351,7 +1341,7 @@ checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1661,7 +1651,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1851,7 +1841,7 @@ dependencies = [ "base64 0.21.7", "byteorder", "flate2", - "nom", + "nom 7.1.3", "num-traits", ] @@ -1865,12 +1855,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -2084,7 +2068,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.106", + "syn", "unic-langid", ] @@ -2098,7 +2082,7 @@ dependencies = [ "i18n-config", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -2238,12 +2222,6 @@ dependencies = [ "icu_properties", ] -[[package]] -name = "if_chain" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd62e6b5e86ea8eeeb8db1de02880a6abc01a397b2ebb64b5d74ac255318f5cb" - [[package]] name = "indexmap" version = "1.9.3" @@ -2308,7 +2286,7 @@ dependencies = [ "indoc", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -2495,7 +2473,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.106", + "syn", ] [[package]] @@ -2641,7 +2619,7 @@ dependencies = [ "quote", "regex-syntax", "rustc_version", - "syn 2.0.106", + "syn", ] [[package]] @@ -2858,6 +2836,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + [[package]] name = "ntapi" version = "0.4.1" @@ -2886,12 +2873,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-conv" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - [[package]] name = "num-integer" version = "0.1.46" @@ -2929,7 +2910,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -3026,7 +3007,6 @@ dependencies = [ "tokio", "toml 0.9.8", "tracing", - "tracing-appender", "tracing-subscriber", ] @@ -3067,8 +3047,6 @@ dependencies = [ "spdlog-rs", "termbg-with-async-stdin", "textwrap", - "tracing", - "tracing-subscriber", ] [[package]] @@ -3082,7 +3060,6 @@ dependencies = [ "regex", "spdlog-rs", "thiserror 2.0.17", - "tracing", "which", "winnow", "zstd", @@ -3106,7 +3083,6 @@ dependencies = [ "spdlog-rs", "tokio", "tokio-util", - "tracing", ] [[package]] @@ -3120,7 +3096,6 @@ dependencies = [ "serde_json", "spdlog-rs", "thiserror 2.0.17", - "tracing", ] [[package]] @@ -3151,7 +3126,6 @@ dependencies = [ "snafu", "spdlog-rs", "toml 0.9.8", - "tracing", ] [[package]] @@ -3181,7 +3155,6 @@ dependencies = [ "sysinfo", "thiserror 2.0.17", "tokio", - "tracing", "zbus", ] @@ -3221,7 +3194,6 @@ dependencies = [ "sysinfo", "thiserror 2.0.17", "tokio", - "tracing", "url", ] @@ -3235,7 +3207,6 @@ dependencies = [ "sequoia-policy-config", "spdlog-rs", "thiserror 2.0.17", - "tracing", ] [[package]] @@ -3253,7 +3224,6 @@ dependencies = [ "spdlog-rs", "thiserror 2.0.17", "tokio", - "tracing", "url", ] @@ -3269,8 +3239,6 @@ dependencies = [ "serde_json", "snafu", "spdlog-rs", - "tracing", - "tracing-subscriber", ] [[package]] @@ -3282,7 +3250,6 @@ dependencies = [ "os-release", "spdlog-rs", "thiserror 2.0.17", - "tracing", "url-escape", "zbus", ] @@ -3322,7 +3289,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -3478,7 +3445,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -3539,12 +3506,6 @@ dependencies = [ "zerovec", ] -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -3567,7 +3528,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.106", + "syn", ] [[package]] @@ -3598,7 +3559,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -3630,7 +3591,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -3995,7 +3956,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.106", + "syn", "walkdir", ] @@ -4262,7 +4223,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -4295,7 +4256,7 @@ checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -4453,10 +4414,10 @@ version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1c97747dbf44bb1ca44a561ece23508e99cb592e862f22222dcf42f51d1e451" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -4481,46 +4442,43 @@ dependencies = [ [[package]] name = "spdlog-internal" -version = "0.1.0" -source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=sink-decouple#6bcb3571d40426443cf764641bc2bc126a08fc24" +version = "0.2.0" +source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=main-dev#eda51be20516ac54c78e87d27a040ec53fffc3a0" dependencies = [ - "nom", - "strum 0.24.1", - "strum_macros 0.24.3", - "thiserror 1.0.69", + "nom 8.0.0", + "strum 0.27.2", + "strum_macros 0.27.2", + "thiserror 2.0.17", ] [[package]] name = "spdlog-macros" -version = "0.2.0" -source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=sink-decouple#6bcb3571d40426443cf764641bc2bc126a08fc24" +version = "0.3.0" +source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=main-dev#eda51be20516ac54c78e87d27a040ec53fffc3a0" dependencies = [ - "nom", "proc-macro2", "quote", "spdlog-internal", - "syn 2.0.106", + "syn", ] [[package]] name = "spdlog-rs" -version = "0.4.3" -source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=sink-decouple#6bcb3571d40426443cf764641bc2bc126a08fc24" +version = "0.5.1" +source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=main-dev#eda51be20516ac54c78e87d27a040ec53fffc3a0" dependencies = [ "arc-swap", "atomic", - "cfg-if", "chrono", "crossbeam", "dyn-clone", - "if_chain", "is-terminal", "libc", "once_cell", "parking_lot", "rustc_version", "spdlog-macros", - "thiserror 1.0.69", + "thiserror 2.0.17", "value-bag", "winapi", ] @@ -4566,46 +4524,45 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.24.1" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ - "strum_macros 0.24.3", + "strum_macros 0.26.4", ] [[package]] name = "strum" -version = "0.26.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" dependencies = [ - "strum_macros 0.26.4", + "strum_macros 0.27.2", ] [[package]] name = "strum_macros" -version = "0.24.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "rustversion", - "syn 1.0.109", + "syn", ] [[package]] name = "strum_macros" -version = "0.26.4" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "rustversion", - "syn 2.0.106", + "syn", ] [[package]] @@ -4692,17 +4649,6 @@ dependencies = [ "sval_nested", ] -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.106" @@ -4731,7 +4677,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -4776,11 +4722,11 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ea5d1b13ca6cff1f9231ffd62f15eefd72543dab5e468735f1a456728a02846" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -4899,7 +4845,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -4910,7 +4856,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -4922,37 +4868,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "time" -version = "0.3.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" -dependencies = [ - "deranged", - "itoa", - "num-conv", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" - -[[package]] -name = "time-macros" -version = "0.2.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" -dependencies = [ - "num-conv", - "time-core", -] - [[package]] name = "tiny-keccak" version = "2.0.2" @@ -5015,7 +4930,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -5229,18 +5144,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-appender" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" -dependencies = [ - "crossbeam-channel", - "thiserror 1.0.69", - "time", - "tracing-subscriber", -] - [[package]] name = "tracing-attributes" version = "0.1.30" @@ -5249,7 +5152,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -5571,7 +5474,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.106", + "syn", "wasm-bindgen-shared", ] @@ -5606,7 +5509,7 @@ checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5771,7 +5674,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -5782,7 +5685,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -6070,7 +5973,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", "synstructure", ] @@ -6117,7 +6020,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.106", + "syn", "zbus_names", "zvariant", "zvariant_utils", @@ -6152,7 +6055,7 @@ checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -6172,7 +6075,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", "synstructure", ] @@ -6212,7 +6115,7 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -6266,7 +6169,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.106", + "syn", "zvariant_utils", ] @@ -6279,6 +6182,6 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.106", + "syn", "winnow", ] diff --git a/Cargo.toml b/Cargo.toml index 2aae8efd0..e66e7629f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ chrono = "0.4.38" rustix = { version = "1", features = ["process", "stdio"] } libc = "0.2.159" reqwest = { version = "0.12.8", default-features = false } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", features = [ +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev", features = [ "multi-thread", "source-location", ], optional = true } @@ -56,7 +56,6 @@ clap_complete = { version = "4.5", features = ["unstable-dynamic"] } clap_lex = "0.7.4" fs4 = "0.13.1" fs_extra = "1.3.0" -tracing-appender = { version = "0.2.3", optional = true } dirs = "6.0.0" termtree = "0.5.1" textwrap = "0.16.2" @@ -107,38 +106,6 @@ openssl = [ ] nice-setup = ["sequoia-nettle-backend", "rustls", "oma-refresh/apt"] openssl-setup = ["sequoia-openssl-backend", "openssl", "oma-refresh/apt"] -spdlog-rs = [ - "dep:spdlog-rs", - "oma-utils/spdlog-rs", - "oma-console/spdlog-rs", - "oma-pm/spdlog-rs", - "oma-refresh/spdlog-rs", - "oma-contents/spdlog-rs", - "oma-fetch/spdlog-rs", - "oma-topics/spdlog-rs", - "oma-history/spdlog-rs", - "oma-repo-verify/spdlog-rs", - "oma-mirror/spdlog-rs", - "apt-auth-config/spdlog-rs", - "oma-tum/spdlog-rs", -] -tracing = [ - "dep:tracing", - "dep:tracing-subscriber", - "dep:tracing-appender", - "oma-utils/tracing", - "oma-console/tracing", - "oma-pm/tracing", - "oma-refresh/tracing", - "oma-contents/tracing", - "oma-fetch/tracing", - "oma-topics/tracing", - "oma-history/tracing", - "oma-repo-verify/tracing", - "oma-mirror/tracing", - "apt-auth-config/tracing", - "oma-tum/tracing", -] default = ["aosc", "nice-setup"] [workspace] diff --git a/apt-auth-config/Cargo.toml b/apt-auth-config/Cargo.toml index 8bce81f03..bbe329183 100644 --- a/apt-auth-config/Cargo.toml +++ b/apt-auth-config/Cargo.toml @@ -7,11 +7,6 @@ license = "MIT" [dependencies] thiserror = "2" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } rust-netrc = "0.1" url = "2.5" - -[features] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] diff --git a/oma-console/Cargo.toml b/oma-console/Cargo.toml index a734f4bb1..665666053 100644 --- a/oma-console/Cargo.toml +++ b/oma-console/Cargo.toml @@ -11,9 +11,7 @@ license = "MIT" chrono = { version = "0.4.38", optional = true } console = { version = "0.16", optional = true } indicatif = { version = "0.18", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } -tracing-subscriber = { version = "0.3", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } ratatui = { version = "0.29", optional = true } # https://github.com/async-rs/async-std/issues/1055 # https://github.com/tokio-rs/tokio/issues/5535 @@ -23,9 +21,7 @@ textwrap = { version = "0.16", optional = true } aho-corasick = { version = "1.1.3", optional = true } [features] -tracing = ["dep:tracing", "dep:tracing-subscriber"] print = ["dep:textwrap", "dep:console", "dep:termbg", "dep:chrono"] pager = ["dep:ratatui", "dep:ansi-to-tui", "dep:console", "dep:aho-corasick"] progress_bar_style = ["dep:indicatif"] -spdlog-rs = ["dep:spdlog-rs"] default = ["print", "pager", "progress_bar_style"] diff --git a/oma-console/examples/msg.rs b/oma-console/examples/msg.rs index a5969d7f0..ef2f8f0d2 100644 --- a/oma-console/examples/msg.rs +++ b/oma-console/examples/msg.rs @@ -1,22 +1,5 @@ -#[cfg(feature = "spdlog-rs")] use oma_console::OmaFormatter; -#[cfg(not(feature = "spdlog-rs"))] -use oma_console::OmaLayer; -#[cfg(not(feature = "spdlog-rs"))] -use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt}; - -#[cfg(not(feature = "spdlog-rs"))] -fn main() { - tracing_subscriber::registry().with(OmaLayer::new()).init(); - tracing::info!("Welcome"); - tracing::debug!("Hello"); - tracing::info!("I'am fine"); - tracing::warn!("Thank you"); - tracing::error!("and you?"); -} - -#[cfg(feature = "spdlog-rs")] fn main() { spdlog::default_logger() .sinks() diff --git a/oma-console/src/lib.rs b/oma-console/src/lib.rs index 2adfd6e71..3a1fd8a2a 100644 --- a/oma-console/src/lib.rs +++ b/oma-console/src/lib.rs @@ -29,10 +29,7 @@ pub mod writer; #[cfg(feature = "print")] pub mod print; -#[cfg(not(all(feature = "print", feature = "spdlog-rs")))] -pub use print::OmaLayer; - -#[cfg(all(feature = "print", feature = "spdlog-rs"))] +#[cfg(feature = "print")] pub use print::OmaFormatter; #[cfg(feature = "print")] diff --git a/oma-console/src/pager.rs b/oma-console/src/pager.rs index a6ece2592..b9550f9e1 100644 --- a/oma-console/src/pager.rs +++ b/oma-console/src/pager.rs @@ -22,11 +22,8 @@ use ratatui::{ }, widgets::Borders, }; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; use termbg::Theme; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; use crate::{print::OmaColorFormat, writer::Writer}; diff --git a/oma-console/src/print.rs b/oma-console/src/print.rs index 90e3e6af0..9a9d59ada 100644 --- a/oma-console/src/print.rs +++ b/oma-console/src/print.rs @@ -1,27 +1,14 @@ -#[cfg(not(feature = "spdlog-rs"))] -use std::collections::BTreeMap; -#[cfg(feature = "spdlog-rs")] use std::fmt::{self, Write}; - use std::{borrow::Cow, time::Duration}; -#[cfg(feature = "spdlog-rs")] use chrono::{DateTime, SecondsFormat, Utc}; use console::{Color, StyledObject, style}; -#[cfg(feature = "spdlog-rs")] use spdlog::{Level, debug, formatter::Formatter}; use termbg::Theme; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{Level, debug, field::Field}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing_subscriber::Layer; pub use termbg; -#[cfg(feature = "spdlog-rs")] use crate::writer::gen_prefix; -#[cfg(not(feature = "spdlog-rs"))] -use crate::writer::{Writeln, Writer}; #[derive(Clone)] enum StyleFollow { @@ -146,7 +133,25 @@ fn term_color(input: D, color: Action) -> StyledObject { } } -#[cfg(feature = "spdlog-rs")] +/// OmaFormatter +/// `OmaFormatter` is used for outputting oma-style logs to `spdlog-rs` +/// +/// # Example: +/// ``` +/// use spdlog::{info, sink::StdStreamSink, Logger}; +/// use oma_console::OmaLayer; +/// +/// let mut logger_builder = Logger::builder(); +/// +/// let logger = logger_builder.sink(Arc::new( +/// StdStreamSink::builder().formatter(Box::new(OmaLayer::default())).build().unwrap() +/// )).build().unwrap(); +/// +/// spdlog::set_default_logger(Arc::new(logger)); +/// +/// info!("My name is oma!"); +/// ``` +/// #[derive(Clone)] pub struct OmaFormatter { with_ansi: bool, @@ -155,7 +160,6 @@ pub struct OmaFormatter { prefix_len: u16, } -#[cfg(feature = "spdlog-rs")] impl Default for OmaFormatter { fn default() -> Self { Self { @@ -167,7 +171,6 @@ impl Default for OmaFormatter { } } -#[cfg(feature = "spdlog-rs")] impl OmaFormatter { pub fn new() -> Self { OmaFormatter::default() @@ -267,7 +270,6 @@ impl OmaFormatter { } } -#[cfg(feature = "spdlog-rs")] impl Formatter for OmaFormatter { fn format( &self, @@ -279,147 +281,3 @@ impl Formatter for OmaFormatter { .map_err(|e| spdlog::Error::FormatRecord(e)) } } - -/// OmaLayer -/// `OmaLayer` is used for outputting oma-style logs to `tracing` -/// -/// # Example: -/// ``` -/// use tracing_subscriber::prelude::*; -/// use oma_console::OmaLayer; -/// use tracing::info; -/// -/// tracing_subscriber::registry() -/// .with(OmaLayer::new()) -/// .init(); -/// -/// info!("My name is oma!"); -/// ``` -/// -#[cfg(not(feature = "spdlog-rs"))] -pub struct OmaLayer { - /// Display result with ansi - with_ansi: bool, - /// A Terminal writer to print oma-style message - writer: Writer, -} - -#[cfg(not(feature = "spdlog-rs"))] -impl Default for OmaLayer { - fn default() -> Self { - Self { - with_ansi: true, - #[cfg(not(feature = "spdlog-rs"))] - writer: Writer::default(), - } - } -} - -#[cfg(not(feature = "spdlog-rs"))] -impl OmaLayer { - pub fn new() -> Self { - OmaLayer::default() - } - - /// Display with ANSI colors - /// - /// Set to false to disable ANSI color sequences. - pub fn with_ansi(mut self, with_ansi: bool) -> Self { - self.with_ansi = with_ansi; - self - } -} - -#[cfg(not(feature = "spdlog-rs"))] -impl Layer for OmaLayer -where - S: tracing::Subscriber, - S: for<'lookup> tracing_subscriber::registry::LookupSpan<'lookup>, -{ - fn on_event( - &self, - event: &tracing::Event<'_>, - _ctx: tracing_subscriber::layer::Context<'_, S>, - ) { - let level = *event.metadata().level(); - - let prefix = if self.with_ansi { - Cow::Owned(match level { - Level::DEBUG => console::style("DEBUG").dim().to_string(), - Level::INFO => console::style("INFO").blue().bold().to_string(), - Level::WARN => console::style("WARNING").yellow().bold().to_string(), - Level::ERROR => console::style("ERROR").red().bold().to_string(), - Level::TRACE => console::style("TRACE").dim().to_string(), - }) - } else { - Cow::Borrowed(match level { - Level::DEBUG => "DEBUG", - Level::INFO => "INFO", - Level::WARN => "WARNING", - Level::ERROR => "ERROR", - Level::TRACE => "TRACE", - }) - }; - - let mut visitor = OmaRecorder(BTreeMap::new()); - event.record(&mut visitor); - - for (k, v) in visitor.0 { - if k == "message" { - if self.with_ansi { - self.writer.writeln(&prefix, &v).ok(); - } else { - self.writer - .writeln(&prefix, &console::strip_ansi_codes(&v)) - .ok(); - } - } - } - } -} -/// OmaRecorder -/// `OmaRecorder` is used for recording oma-style logs. -/// -/// # Example: -/// ```ignore -/// let mut visitor = OmaRecorder(BTreeMap::new()); -/// event.record(&mut visitor); -/// for (k, v) in visitor.0 { -/// if k == "message" { -/// self.writer.writeln(&prefix, &v).ok(); -/// } -/// } -/// ``` -#[cfg(not(feature = "spdlog-rs"))] -struct OmaRecorder<'a>(BTreeMap<&'a str, String>); - -#[cfg(not(feature = "spdlog-rs"))] -impl tracing::field::Visit for OmaRecorder<'_> { - fn record_f64(&mut self, field: &Field, value: f64) { - self.0.insert(field.name(), value.to_string()); - } - - fn record_i64(&mut self, field: &Field, value: i64) { - self.0.insert(field.name(), value.to_string()); - } - - fn record_u64(&mut self, field: &Field, value: u64) { - self.0.insert(field.name(), value.to_string()); - } - - fn record_bool(&mut self, field: &Field, value: bool) { - self.0.insert(field.name(), value.to_string()); - } - - fn record_str(&mut self, field: &Field, value: &str) { - self.0.insert(field.name(), value.to_string()); - } - - fn record_error(&mut self, field: &Field, value: &(dyn std::error::Error + 'static)) { - self.0.insert(field.name(), format!("{value:#?}")); - } - - fn record_debug(&mut self, field: &Field, value: &dyn std::fmt::Debug) { - self.0.insert(field.name(), format!("{value:#?}")); - } -} diff --git a/oma-contents/Cargo.toml b/oma-contents/Cargo.toml index 02c9dcd69..0aef71e7b 100644 --- a/oma-contents/Cargo.toml +++ b/oma-contents/Cargo.toml @@ -14,13 +14,10 @@ winnow = "0.7" flate2 = "1.0" rayon = "1.8" lzzzz = "2.0" -tracing = { version = "0.1", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } which = "8" zstd = "0.13" memchr = "2" [features] aosc = [] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] diff --git a/oma-contents/src/searcher.rs b/oma-contents/src/searcher.rs index ac6e3d98b..23682ad4e 100644 --- a/oma-contents/src/searcher.rs +++ b/oma-contents/src/searcher.rs @@ -14,10 +14,7 @@ use flate2::bufread::GzDecoder; use lzzzz::lz4f::BufReadDecompressor; use memchr::memmem; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; use zstd::Decoder; use crate::{OmaContentsError, parser::parse_contents_single_line}; diff --git a/oma-fetch/Cargo.toml b/oma-fetch/Cargo.toml index 2f810932b..ca95f566a 100644 --- a/oma-fetch/Cargo.toml +++ b/oma-fetch/Cargo.toml @@ -20,8 +20,7 @@ async-compression = { version = "=0.4.27", features = ["gzip", "xz", "futures-io # even with older liblzma (Ubuntu 22.04 uses 5.2.x). Be mindful, however, that # async-compression depends on a different liblzma-rs than what is specified here. liblzma = { version = "0", features = ["uncheck_liblzma_version"] } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } tokio-util = { version = "0.7", features = ["compat"] } md-5 = "0.10.6" bon = "3" @@ -34,6 +33,4 @@ flume = "0.11.1" [features] rustls = ["reqwest/rustls-tls"] native-tls = ["reqwest/native-tls"] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] default = ["rustls"] diff --git a/oma-fetch/src/download.rs b/oma-fetch/src/download.rs index 91f1d2143..5b8be3150 100644 --- a/oma-fetch/src/download.rs +++ b/oma-fetch/src/download.rs @@ -16,17 +16,13 @@ use reqwest::{ header::{ACCEPT_RANGES, CONTENT_LENGTH, HeaderValue, RANGE}, }; use snafu::{ResultExt, Snafu}; +use spdlog::{debug, trace}; use tokio::{ fs::{self, File}, io::{AsyncBufReadExt as _, AsyncReadExt as _, AsyncSeekExt, AsyncWriteExt}, time::timeout, }; - -#[cfg(feature = "spdlog-rs")] -use spdlog::{debug, trace}; use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, trace}; use crate::{DownloadEntry, DownloadSourceType}; diff --git a/oma-fetch/src/lib.rs b/oma-fetch/src/lib.rs index fc0d9d2af..c0b0625e2 100644 --- a/oma-fetch/src/lib.rs +++ b/oma-fetch/src/lib.rs @@ -4,12 +4,8 @@ use bon::{Builder, builder}; use checksum::Checksum; use download::{BuilderError, SingleDownloader, SuccessSummary}; use futures::StreamExt; - use reqwest::{Client, Method, RequestBuilder, Response}; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; pub mod checksum; pub mod download; diff --git a/oma-history/Cargo.toml b/oma-history/Cargo.toml index e167a8110..3c3e34b64 100644 --- a/oma-history/Cargo.toml +++ b/oma-history/Cargo.toml @@ -12,13 +12,8 @@ oma-pm-operation-type = { version = "0.9", path = "../oma-pm-operation-type" } rusqlite = { version = "0.37", features = ["bundled"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tracing = { version = "0.1", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } thiserror = "2" [dev-dependencies] chrono = "0.4" - -[features] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] diff --git a/oma-history/src/lib.rs b/oma-history/src/lib.rs index 3d184bd05..07b499e9d 100644 --- a/oma-history/src/lib.rs +++ b/oma-history/src/lib.rs @@ -11,11 +11,8 @@ use migrations::create_and_maybe_migration_from_oma_db_v2; use oma_pm_operation_type::{InstallOperation, OmaOperation, RemoveTag}; use rusqlite::{Connection, Error, Result}; use serde::Deserialize; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; use thiserror::Error; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; pub struct HistoryEntryInner { pub install: Vec, diff --git a/oma-history/src/migrations.rs b/oma-history/src/migrations.rs index bea6fcb09..d1cb624d2 100644 --- a/oma-history/src/migrations.rs +++ b/oma-history/src/migrations.rs @@ -2,10 +2,7 @@ use oma_pm_operation_type::{InstallOperation, RemoveTag}; use rusqlite::Connection; use serde::Deserialize; use serde_json::Value; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, info, warn}; use crate::{ HistoryEntryInner, HistoryError, HistoryResult, INSERT_INSTALL_TABLE, INSERT_NEW_MAIN_TABLE, diff --git a/oma-mirror/Cargo.toml b/oma-mirror/Cargo.toml index 6ccc9e915..652be1e6b 100644 --- a/oma-mirror/Cargo.toml +++ b/oma-mirror/Cargo.toml @@ -11,11 +11,6 @@ serde_json = "1.0" snafu = "0.8.5" indexmap = { version = "2.6", features = ["serde"] } ahash = "0.8.11" -tracing = { version = "0.1", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } once_cell = "1.19" toml = { version = "0.9", features = ["preserve_order"] } - -[features] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] diff --git a/oma-mirror/src/lib.rs b/oma-mirror/src/lib.rs index ab74cf608..68b1d7624 100644 --- a/oma-mirror/src/lib.rs +++ b/oma-mirror/src/lib.rs @@ -11,10 +11,7 @@ use indexmap::{IndexMap, indexmap}; use once_cell::sync::OnceCell; use serde::{Deserialize, Serialize}; use snafu::{ResultExt, Snafu}; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; use crate::parser::{ MirrorConfig, MirrorConfigTemplate, MirrorsConfig, MirrorsConfigTemplate, TemplateParseError, diff --git a/oma-pm/Cargo.toml b/oma-pm/Cargo.toml index 8f494db59..69c38426d 100644 --- a/oma-pm/Cargo.toml +++ b/oma-pm/Cargo.toml @@ -24,8 +24,7 @@ tokio = { version = "1.15", default-features = false, features = [ "rt-multi-thread", ] } fs4 = "0.13" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } oma-pm-operation-type = { version = "0.9", path = "../oma-pm-operation-type" } zbus = { version = "5.1", features = ["tokio"] } cxx = "1.0.121" @@ -45,5 +44,3 @@ flume = "0.11" [features] aosc = ["dep:sysinfo"] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] diff --git a/oma-pm/src/apt.rs b/oma-pm/src/apt.rs index 05b560aac..cbc54b7a9 100644 --- a/oma-pm/src/apt.rs +++ b/oma-pm/src/apt.rs @@ -27,15 +27,9 @@ use oma_fetch::{Event, Summary, checksum::ChecksumError, reqwest::Client}; use oma_utils::{dpkg::DpkgError, human_bytes::HumanBytes, is_termux}; pub use oma_apt::config::Config as AptConfig; -#[cfg(feature = "spdlog-rs")] -use spdlog::{debug, error}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, error}; - -#[cfg(all(feature = "aosc", feature = "spdlog-rs"))] +#[cfg(feature = "aosc")] use spdlog::warn; -#[cfg(all(feature = "aosc", not(feature = "spdlog-rs")))] -use tracing::warn; +use spdlog::{debug, error}; pub use oma_pm_operation_type::*; use zbus::Connection; diff --git a/oma-pm/src/commit.rs b/oma-pm/src/commit.rs index 7b8b19b2b..0e27e5e47 100644 --- a/oma-pm/src/commit.rs +++ b/oma-pm/src/commit.rs @@ -9,11 +9,8 @@ use oma_apt::{ }; use oma_fetch::{Event, Summary, reqwest::Client}; use oma_pm_operation_type::{InstallEntry, OmaOperation}; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; use std::io::Write; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; use crate::{ apt::{DownloadConfig, InstallProgressOpt, OmaApt, OmaAptError, OmaAptResult}, diff --git a/oma-pm/src/dbus.rs b/oma-pm/src/dbus.rs index c071f8c84..dcfdb7f22 100644 --- a/oma-pm/src/dbus.rs +++ b/oma-pm/src/dbus.rs @@ -1,7 +1,4 @@ -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; use zbus::{Connection, Result, interface, proxy}; pub struct OmaBus { diff --git a/oma-pm/src/download.rs b/oma-pm/src/download.rs index a72af7359..0fd120070 100644 --- a/oma-pm/src/download.rs +++ b/oma-pm/src/download.rs @@ -6,10 +6,7 @@ use oma_fetch::{ }; use oma_pm_operation_type::InstallEntry; use oma_utils::url_no_escape::url_no_escape_times; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; use crate::{ CustomDownloadMessage, diff --git a/oma-pm/src/matches.rs b/oma-pm/src/matches.rs index 320856441..385e8c13c 100644 --- a/oma-pm/src/matches.rs +++ b/oma-pm/src/matches.rs @@ -14,10 +14,7 @@ use oma_utils::{ url_no_escape::url_no_escape, }; use once_cell::sync::OnceCell; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, info}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, info}; use crate::pkginfo::{OmaPackage, OmaPackageWithoutVersion, PtrIsNone}; diff --git a/oma-pm/src/utils.rs b/oma-pm/src/utils.rs index 2c17f6293..6a649d63d 100644 --- a/oma-pm/src/utils.rs +++ b/oma-pm/src/utils.rs @@ -1,8 +1,5 @@ -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, warn}; use std::{fs, io, path::Path}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, warn}; #[cfg(feature = "aosc")] pub fn pkg_is_current_kernel( diff --git a/oma-refresh/Cargo.toml b/oma-refresh/Cargo.toml index a257d49b6..1f61be605 100644 --- a/oma-refresh/Cargo.toml +++ b/oma-refresh/Cargo.toml @@ -11,17 +11,12 @@ license = "GPL-3.0-or-later" oma-fetch = { version = "^0.34.0", path = "../oma-fetch", default-features = false } thiserror = "2" url = "2.3" -tokio = { version = "1.28", default-features = false, features = [ - "fs", - "process", - "macros", -] } +tokio = { version = "1.28", default-features = false, features = ["fs", "process", "macros"] } futures = "0.3" oma-apt-sources-lists = "0.9" chrono = { version = "0.4", features = ["unstable-locales"] } oma-topics = { version = "^0.25.0", path = "../oma-topics", optional = true, default-features = false } -tracing = { version = "0.1", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } oma-repo-verify = { version = "^0.9.0", path = "../oma-repo-verify", default-features = false } ahash = "0.8.11" oma-apt = { version = "0.11", optional = true } @@ -46,14 +41,10 @@ rustls = ["oma-fetch/rustls", "oma-topics/rustls"] native-tls = ["oma-fetch/native-tls", "oma-topics/native-tls"] apt = ["dep:oma-apt"] blocking = ["tokio/rt", "tokio/rt-multi-thread"] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] default = ["aosc", "sequoia-nettle-backend", "rustls", "apt"] [dev-dependencies] -tokio = { version = "1.28", default-features = false, features = [ - "rt-multi-thread", -] } +tokio = { version = "1.28", default-features = false, features = ["rt-multi-thread"] } flume = "0.11.1" oma-utils = { version = "^0.12.0", path = "../oma-utils", features = ["dpkg"] } diff --git a/oma-refresh/src/config.rs b/oma-refresh/src/config.rs index 1f8010e54..6092f4471 100644 --- a/oma-refresh/src/config.rs +++ b/oma-refresh/src/config.rs @@ -6,10 +6,7 @@ use aho_corasick::AhoCorasick; use oma_apt::config::{Config, ConfigTree}; use oma_fetch::CompressFile; use once_cell::sync::OnceCell; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; use crate::{db::RefreshError, inrelease::ChecksumItem}; diff --git a/oma-refresh/src/db.rs b/oma-refresh/src/db.rs index 3c22e84ec..c84f350e8 100644 --- a/oma-refresh/src/db.rs +++ b/oma-refresh/src/db.rs @@ -41,15 +41,12 @@ use oma_fetch::reqwest::StatusCode; use oma_utils::is_termux; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, warn}; use sysinfo::{Pid, System}; use tokio::{ fs::{self}, task::spawn_blocking, }; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, warn}; use crate::sourceslist::{MirrorSource, MirrorSources, scan_sources_list_from_paths}; use crate::{ diff --git a/oma-refresh/src/inrelease.rs b/oma-refresh/src/inrelease.rs index f3ec3641a..2ea25778a 100644 --- a/oma-refresh/src/inrelease.rs +++ b/oma-refresh/src/inrelease.rs @@ -3,7 +3,6 @@ use deb822_fast::{FromDeb822, FromDeb822Paragraph, Paragraph}; use oma_apt_sources_lists::Signature; use oma_repo_verify::verify_release_by_sysroot; use once_cell::sync::OnceCell; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, trace}; use std::{ borrow::Cow, @@ -14,8 +13,6 @@ use std::{ str::FromStr, }; use thiserror::Error; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, trace}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ChecksumItem { diff --git a/oma-refresh/src/sourceslist.rs b/oma-refresh/src/sourceslist.rs index a432e9ba7..9e7b72596 100644 --- a/oma-refresh/src/sourceslist.rs +++ b/oma-refresh/src/sourceslist.rs @@ -17,14 +17,11 @@ use oma_fetch::{ send_request, }; use once_cell::sync::OnceCell; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, warn}; use tokio::{ fs::{self, File}, io::AsyncWriteExt, }; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, warn}; use url::Url; use crate::{ diff --git a/oma-repo-verify/Cargo.toml b/oma-repo-verify/Cargo.toml index 2b7eb58fb..0f33b5f00 100644 --- a/oma-repo-verify/Cargo.toml +++ b/oma-repo-verify/Cargo.toml @@ -9,14 +9,11 @@ license = "MIT" anyhow = "1" thiserror = "2" sequoia-openpgp = { version = "2", default-features = false } -spdlog-rs = { git = 'https://github.com/SpriteOvO/spdlog-rs.git', branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } +spdlog-rs = { git = 'https://github.com/SpriteOvO/spdlog-rs.git', branch = "main-dev" } oma-apt-sources-lists = "0.9" sequoia-policy-config = "0.8" [features] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] sequoia-openssl-backend = ["sequoia-openpgp/crypto-openssl"] sequoia-nettle-backend = ["sequoia-openpgp/crypto-nettle"] default = ["sequoia-nettle-backend"] diff --git a/oma-repo-verify/src/lib.rs b/oma-repo-verify/src/lib.rs index ae11af5ce..b6849aae5 100644 --- a/oma-repo-verify/src/lib.rs +++ b/oma-repo-verify/src/lib.rs @@ -18,10 +18,7 @@ use sequoia_openpgp::{ policy::StandardPolicy, }; use sequoia_policy_config::ConfiguredStandardPolicy; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; #[derive(Debug)] pub struct InReleaseVerifier { diff --git a/oma-topics/Cargo.toml b/oma-topics/Cargo.toml index 5923b7aa2..1fd07fcb5 100644 --- a/oma-topics/Cargo.toml +++ b/oma-topics/Cargo.toml @@ -11,15 +11,10 @@ license = "MIT" reqwest = { version = "0.12", features = ["json"], default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tokio = { version = "1.28", default-features = false, features = [ - "fs", - "rt", - "rt-multi-thread", -] } +tokio = { version = "1.28", default-features = false, features = ["fs", "rt", "rt-multi-thread"] } thiserror = "2.0" futures = "0.3" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } url = "2.5" oma-mirror = { version = "0.7.0", path = "../oma-mirror" } ahash = "0.8.11" @@ -27,14 +22,9 @@ ahash = "0.8.11" [dev-dependencies] oma-inquire = "0.3" oma-console = { path = "../oma-console" } -tokio = { version = "1.28", default-features = false, features = [ - "macros", - "rt-multi-thread", -] } +tokio = { version = "1.28", default-features = false, features = ["macros", "rt-multi-thread"] } [features] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] rustls = ["reqwest/rustls-tls"] native-tls = ["reqwest/native-tls"] default = ["rustls"] diff --git a/oma-topics/src/lib.rs b/oma-topics/src/lib.rs index ff52bf155..c716cfab2 100644 --- a/oma-topics/src/lib.rs +++ b/oma-topics/src/lib.rs @@ -9,11 +9,8 @@ use futures::future::try_join_all; use oma_mirror::{MirrorError, MirrorManager, parser::MirrorsConfigTemplate, write_sources_inner}; use reqwest::Client; use serde::{Deserialize, Serialize, de::DeserializeOwned}; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, warn}; use tokio::fs; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, warn}; use url::Url; pub type Result = std::result::Result; diff --git a/oma-tum/Cargo.toml b/oma-tum/Cargo.toml index d9a097a2e..4161b5004 100644 --- a/oma-tum/Cargo.toml +++ b/oma-tum/Cargo.toml @@ -11,14 +11,6 @@ snafu = "0.8.6" serde = { version = "1", features = ["derive"] } serde_json = "1" ahash = "0.8.12" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } logos = "0.15" debversion = "0.4.5" - -[dev-dependencies] -tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } - -[features] -spdlog-rs = ["dep:spdlog-rs"] -tracing = ["dep:tracing"] diff --git a/oma-tum/examples/tum.rs b/oma-tum/examples/tum.rs index 32bb931a0..4e11ebf83 100644 --- a/oma-tum/examples/tum.rs +++ b/oma-tum/examples/tum.rs @@ -2,11 +2,8 @@ use std::path::Path; use oma_pm_operation_type::{InstallEntry, InstallOperation, OmaOperation, PackageUrl}; use oma_tum::{get_matches_tum, get_tum}; -use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt}; fn main() { - tracing_subscriber::registry().with(fmt::layer()).init(); - let dir = Path::new(env!("CARGO_MANIFEST_DIR")); let tum = get_tum(&dir.join("examples/tum")).unwrap(); let tum = get_matches_tum( diff --git a/oma-tum/src/lib.rs b/oma-tum/src/lib.rs index 449a9bafe..3d02856d0 100644 --- a/oma-tum/src/lib.rs +++ b/oma-tum/src/lib.rs @@ -10,10 +10,7 @@ use debversion::Version; use oma_pm_operation_type::{InstallOperation, OmaOperation}; use serde::Deserialize; use snafu::{ResultExt, Snafu, Whatever}; -#[cfg(feature = "spdlog-rs")] use spdlog::warn; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::warn; use crate::parser::{VersionToken, parse_version_expr}; diff --git a/oma-utils/Cargo.toml b/oma-utils/Cargo.toml index 63b7b75ca..a42bcd3de 100644 --- a/oma-utils/Cargo.toml +++ b/oma-utils/Cargo.toml @@ -13,8 +13,7 @@ number_prefix = { version = "0.4", optional = true } os-release = "0.1" zbus = { version = "5.1", optional = true } url-escape = { version = "0.1", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "sink-decouple", optional = true } -tracing = { version = "0.1", optional = true } +spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev"} logind-zbus = "5.1" [features] diff --git a/oma-utils/src/dpkg/mod.rs b/oma-utils/src/dpkg/mod.rs index b7b43df9e..cd5559013 100644 --- a/oma-utils/src/dpkg/mod.rs +++ b/oma-utils/src/dpkg/mod.rs @@ -4,10 +4,7 @@ use std::{ process::{Command, Stdio}, }; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; #[derive(Debug, thiserror::Error)] pub enum DpkgError { diff --git a/src/config.rs b/src/config.rs index cc7829365..d27b33402 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,9 +1,7 @@ use crate::fl; use serde::{Deserialize, Serialize}; -#[cfg(feature = "spdlog-rs")] + use spdlog::{error, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{error, warn}; #[cfg(feature = "aosc")] const DEFAULT_CONFIG: &str = include_str!("../data/config/oma.toml"); @@ -208,6 +206,7 @@ impl Config { .unwrap_or_else(GeneralConfig::default_bell) } + #[allow(dead_code)] pub fn save_log_count(&self) -> usize { self.general .as_ref() diff --git a/src/error.rs b/src/error.rs index 2d05c58b7..c2f131b5a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,10 +29,7 @@ use oma_utils::dpkg::DpkgError; #[cfg(feature = "aosc")] use oma_topics::OmaTopicsError; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, error, info}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, error, info}; use crate::subcommand::utils::LockError; use crate::{due_to, fl, msg}; diff --git a/src/main.rs b/src/main.rs index 6796bc6e3..5258ede33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,13 @@ use std::env::{self, args}; use std::ffi::CString; -use std::fs::{create_dir_all, read_dir, remove_file}; +use std::fs::create_dir_all; use std::io::{self, IsTerminal, stderr, stdin}; use std::path::{Path, PathBuf}; use std::process::{Command, exit}; -#[cfg(feature = "spdlog-rs")] + use std::sync::Arc; use std::sync::{LazyLock, OnceLock}; -use std::thread; use std::time::{Duration, SystemTime, UNIX_EPOCH}; mod args; @@ -31,10 +30,7 @@ use clap_i18n_richformatter::{ClapI18nRichFormatter, init_clap_rich_formatter_lo use error::OutputError; use i18n_embed::{DesktopLanguageRequester, Localizer}; use lang::LANGUAGE_LOADER; -#[cfg(feature = "spdlog-rs")] use oma_console::OmaFormatter; -#[cfg(not(feature = "spdlog-rs"))] -use oma_console::OmaLayer; use oma_console::print::{OmaColorFormat, termbg}; use oma_console::writer::{MessageType, Writer, writeln_inner}; use oma_pm::apt::AptConfig; @@ -43,7 +39,6 @@ use oma_utils::{OsRelease, is_termux}; use reqwest::Client; use rustix::stdio::stdout; // FIXME: `spdlog::error` is conflict with `mod error` -#[cfg(feature = "spdlog-rs")] use spdlog::{ Level, LevelFilter, Logger, debug, default_logger, error as error2, info, set_default_logger, sink::{AsyncPoolSink, RotatingFileSink, RotationPolicy, StdStreamSink}, @@ -51,14 +46,6 @@ use spdlog::{ }; use subcommand::utils::{LockError, is_terminal}; use tokio::runtime::Runtime; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, error as error2, info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing_appender::non_blocking::WorkerGuard; -#[cfg(not(feature = "spdlog-rs"))] -use tracing_subscriber::{ - EnvFilter, Layer, fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, -}; use tui::Tui; use utils::{is_root, is_ssh_from_loginctl}; @@ -298,25 +285,9 @@ fn init_localizer() { LANGUAGE_LOADER.set_use_isolating(false); } -macro_rules! init_logger_inner { - ($context:ident, $non_blocking:ident) => {{ - let debug_filter: EnvFilter = "hyper=off,rustls=off,debug".parse().unwrap(); - $context - .with( - fmt::layer() - .with_file(true) - .with_writer($non_blocking) - .with_filter(debug_filter), - ) - .init() - }}; - ($context:ident) => {{ $context.init() }}; -} - -#[cfg(feature = "spdlog-rs")] fn init_logger( oma: &OhManagerAilurus, - config: &Config, + _config: &Config, ) -> (Option>, anyhow::Result) { let debug = oma.global.debug; let dry_run = oma.global.dry_run; @@ -390,119 +361,6 @@ fn init_logger( (Some(default_logger()), log_file) } -#[cfg(not(feature = "spdlog-rs"))] -fn init_logger( - oma: &OhManagerAilurus, - config: &Config, -) -> (Option, anyhow::Result) { - let debug = oma.global.debug; - let dry_run = oma.global.dry_run; - - let log_dir = if is_root() { - PathBuf::from("/var/log/oma") - } else { - dirs::state_dir() - .expect("Failed to get state dir") - .join("oma") - }; - - let log_file = create_log_file(&log_dir); - let mut log_guard = None; - - if !debug && !dry_run { - let no_i18n_embd: EnvFilter = "i18n_embed=off,info".parse().unwrap(); - - let context = tracing_subscriber::registry().with( - OmaLayer::new() - .with_ansi(enable_ansi(oma)) - .with_filter(no_i18n_embd), - ); - - if let Ok(log_file) = &log_file { - let file_appender = tracing_appender::rolling::never(&log_dir, log_file); - let (non_blocking, guard) = tracing_appender::non_blocking(file_appender); - init_logger_inner!(context, non_blocking); - log_guard = Some(guard); - } else { - init_logger_inner!(context); - } - } else { - let filter = EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "hyper=off,rustls=off,debug".parse().unwrap()); - - let context = tracing_subscriber::registry().with( - fmt::layer() - .event_format( - tracing_subscriber::fmt::format() - .with_file(true) - .with_line_number(true) - .with_ansi(enable_ansi(oma)), - ) - .with_filter(filter), - ); - - if let Ok(log_file) = &log_file { - let file_appender = tracing_appender::rolling::never(&log_dir, log_file); - let (non_blocking, guard) = tracing_appender::non_blocking(file_appender); - init_logger_inner!(context, non_blocking); - log_guard = Some(guard); - } else { - init_logger_inner!(context); - } - } - - // 日志文件创建成功再去遍历文件 - if log_file.is_ok() { - thread::scope(|s| { - s.spawn(|| { - let mut v = vec![]; - let dirs = read_dir(&log_dir) - .expect("Failed to read log dir") - .collect::>(); - - for p in &dirs { - let Ok(p) = p else { - continue; - }; - - let file_name = p.file_name(); - let file_name = file_name.to_string_lossy(); - let Some((prefix, timestamp)) = file_name.rsplit_once('.') else { - continue; - }; - - if prefix != "oma.log" { - continue; - } - - let Ok(timestamp) = timestamp.parse::() else { - continue; - }; - - v.push(timestamp); - } - - if v.len() > config.save_log_count() { - v.sort_unstable_by(|a, b| b.cmp(a)); - - for _ in 1..=(v.len() - config.save_log_count()) { - let Some(pop) = v.pop() else { - break; - }; - - let log_path = log_dir.join(format!("oma.log.{pop}")); - if let Err(e) = remove_file(&log_path) { - debug!("Failed to remove file {}: {}", log_path.display(), e); - } - } - } - }); - }); - } - - (log_guard, log_file) -} - fn create_log_file(log_dir: &Path) -> anyhow::Result { create_dir_all(log_dir)?; @@ -797,6 +655,3 @@ fn single_handler() { std::process::exit(130); } - -#[cfg(all(feature = "spdlog-rs", feature = "tracing"))] -compile_error!("feature spdlog-rs and tracing should not be enabled at the same time"); diff --git a/src/path_completions.rs b/src/path_completions.rs index babc73615..c91df1de5 100644 --- a/src/path_completions.rs +++ b/src/path_completions.rs @@ -6,10 +6,7 @@ use clap_complete::{CompletionCandidate, engine::ValueCompleter}; use clap_lex::OsStrExt; use dirs::home_dir; use rustix::path::Arg; -#[cfg(feature = "spdlog-rs")] use spdlog::debug; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::debug; /// Complete a value as a [`std::path::Path`] /// diff --git a/src/pb.rs b/src/pb.rs index a8bec2db0..3e82c1d2c 100644 --- a/src/pb.rs +++ b/src/pb.rs @@ -19,10 +19,7 @@ use crate::{WRITER, error::Chain, fl, install_progress::osc94_progress, msg, uti use crate::{color_formatter, error::OutputError}; use oma_refresh::db::Event as RefreshEvent; use oma_utils::human_bytes::HumanBytes; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, error, info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, error, info, warn}; pub trait RenderPackagesDownloadProgress { fn render_progress(&mut self, rx: &flume::Receiver, download_only: bool); diff --git a/src/subcommand/clean.rs b/src/subcommand/clean.rs index 3e7b6ba65..604bc5332 100644 --- a/src/subcommand/clean.rs +++ b/src/subcommand/clean.rs @@ -9,10 +9,7 @@ use clap::Args; use fs_extra::dir::get_size; use oma_console::indicatif::HumanBytes; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, error, info}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, error, info}; use crate::{error::OutputError, utils::root}; diff --git a/src/subcommand/command_not_found.rs b/src/subcommand/command_not_found.rs index ece45ab78..d083fb797 100644 --- a/src/subcommand/command_not_found.rs +++ b/src/subcommand/command_not_found.rs @@ -7,10 +7,8 @@ use oma_console::print::Action; use oma_contents::OmaContentsError; use oma_contents::searcher::{Mode, search}; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; -#[cfg(feature = "spdlog-rs")] + use spdlog::error; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::error; use crate::config::Config; use crate::error::OutputError; diff --git a/src/subcommand/download.rs b/src/subcommand/download.rs index 006465fc2..680055d79 100644 --- a/src/subcommand/download.rs +++ b/src/subcommand/download.rs @@ -6,10 +6,7 @@ use clap_complete::ArgValueCompleter; use flume::unbounded; use oma_pm::apt::{AptConfig, DownloadConfig, OmaApt, OmaAptArgs}; use oma_pm::matches::PackagesMatcher; -#[cfg(feature = "spdlog-rs")] use spdlog::error; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::error; use crate::config::Config; use crate::pb::{NoProgressBar, OmaMultiProgressBar, RenderPackagesDownloadProgress}; diff --git a/src/subcommand/history.rs b/src/subcommand/history.rs index f8bf43d9b..278bad1f2 100644 --- a/src/subcommand/history.rs +++ b/src/subcommand/history.rs @@ -9,10 +9,7 @@ use oma_pm::matches::{GetArchMethod, PackagesMatcher}; use oma_pm::oma_apt::PackageSort; use oma_pm::pkginfo::PtrIsNone; use oma_pm::{apt::OmaApt, pkginfo::OmaPackage}; -#[cfg(feature = "spdlog-rs")] use spdlog::warn; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::warn; use std::path::{Path, PathBuf}; use std::sync::atomic::Ordering; diff --git a/src/subcommand/install.rs b/src/subcommand/install.rs index 6f4f63402..c032b970d 100644 --- a/src/subcommand/install.rs +++ b/src/subcommand/install.rs @@ -7,10 +7,7 @@ use oma_pm::apt::OmaApt; use oma_pm::apt::OmaAptArgs; use oma_pm::matches::GetArchMethod; use oma_pm::matches::PackagesMatcher; -#[cfg(feature = "spdlog-rs")] use spdlog::{info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{info, warn}; use crate::HTTP_CLIENT; use crate::args::ARG_HELP_HEADING; diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index 64dc69cb3..0bac841dd 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -7,10 +7,7 @@ use oma_pm::{ apt::{AptConfig, OmaApt, OmaAptArgs}, oma_apt::{PackageSort, PkgCurrentState, PkgSelectedState}, }; -#[cfg(feature = "spdlog-rs")] use spdlog::info; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::info; use crate::{NOT_DISPLAY_ABORT, fl, utils::pkgnames_completions}; use crate::{color_formatter, config::Config, error::OutputError, table::PagerPrinter}; diff --git a/src/subcommand/mark.rs b/src/subcommand/mark.rs index 862f2d6bb..88e9da4f3 100644 --- a/src/subcommand/mark.rs +++ b/src/subcommand/mark.rs @@ -7,10 +7,7 @@ use oma_pm::{ apt::{AptConfig, OmaApt, OmaAptArgs}, matches::{GetArchMethod, PackagesMatcher}, }; -#[cfg(feature = "spdlog-rs")] use spdlog::info; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::info; use crate::{ color_formatter, diff --git a/src/subcommand/mirror.rs b/src/subcommand/mirror.rs index 5acaa90fc..f86f5683e 100644 --- a/src/subcommand/mirror.rs +++ b/src/subcommand/mirror.rs @@ -28,11 +28,8 @@ use oma_utils::dpkg::dpkg_arch; use reqwest::blocking; use sha2::Digest; use sha2::Sha256; -#[cfg(feature = "spdlog-rs")] use spdlog::{error, info, warn}; use tabled::Tabled; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{error, info, warn}; use crate::APP_USER_AGENT; use crate::HTTP_CLIENT; diff --git a/src/subcommand/refresh.rs b/src/subcommand/refresh.rs index 4a40159a1..bbbd4b3bd 100644 --- a/src/subcommand/refresh.rs +++ b/src/subcommand/refresh.rs @@ -2,10 +2,7 @@ use std::path::PathBuf; use clap::Args; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; -#[cfg(feature = "spdlog-rs")] use spdlog::info; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::info; use crate::config::Config; use crate::{HTTP_CLIENT, fl, success}; diff --git a/src/subcommand/remove.rs b/src/subcommand/remove.rs index 1b31d9ec1..a60bdacf3 100644 --- a/src/subcommand/remove.rs +++ b/src/subcommand/remove.rs @@ -8,10 +8,7 @@ use dialoguer::theme::ColorfulTheme; use dialoguer::{Confirm, Input}; use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs}; use oma_pm::matches::{GetArchMethod, PackagesMatcher}; -#[cfg(feature = "spdlog-rs")] use spdlog::{info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{info, warn}; use crate::config::Config; use crate::fl; diff --git a/src/subcommand/show.rs b/src/subcommand/show.rs index 2ff847937..b84b35f94 100644 --- a/src/subcommand/show.rs +++ b/src/subcommand/show.rs @@ -10,10 +10,7 @@ use oma_pm::{ oma_apt::records::RecordField, pkginfo::{AptSource, OmaPackage}, }; -#[cfg(feature = "spdlog-rs")] use spdlog::info; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::info; use crate::{config::Config, error::OutputError, utils::pkgnames_and_path_completions}; diff --git a/src/subcommand/size_analyzer.rs b/src/subcommand/size_analyzer.rs index 5e997aec1..1c369cae8 100644 --- a/src/subcommand/size_analyzer.rs +++ b/src/subcommand/size_analyzer.rs @@ -25,13 +25,10 @@ use ratatui::{ layout::{Direction, Layout}, prelude::Backend, }; -#[cfg(feature = "spdlog-rs")] use spdlog::info; use std::io::Write; use tabled::builder::Builder; use tabled::settings::{Alignment, Settings}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::info; use crate::utils::{dbus_check, is_root}; use crate::{CliExecuter, config::Config, error::OutputError}; diff --git a/src/subcommand/topics.rs b/src/subcommand/topics.rs index 707435bd6..e0338943a 100644 --- a/src/subcommand/topics.rs +++ b/src/subcommand/topics.rs @@ -19,12 +19,9 @@ use oma_pm::{ }; use oma_utils::dpkg::dpkg_arch; use once_cell::sync::OnceCell; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, error, info, warn}; use sysinfo::System; use tokio::task::spawn_blocking; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, error, info, warn}; use crate::{ HTTP_CLIENT, NOT_ALLOW_CTRLC, RT, diff --git a/src/subcommand/tree.rs b/src/subcommand/tree.rs index 63f181c4b..38195ed1f 100644 --- a/src/subcommand/tree.rs +++ b/src/subcommand/tree.rs @@ -16,7 +16,7 @@ use oma_pm::{ oma_apt::{BaseDep, Package, Version}, pkginfo::OmaDepType, }; -use tracing::{debug, trace}; +use spdlog::{debug, trace}; use crate::{ CliExecuter, config::Config, error::OutputError, fl, table::oma_display_with_normal_output, diff --git a/src/subcommand/upgrade.rs b/src/subcommand/upgrade.rs index 6451dbbee..92adba4b1 100644 --- a/src/subcommand/upgrade.rs +++ b/src/subcommand/upgrade.rs @@ -12,11 +12,7 @@ use oma_pm::apt::Upgrade as AptUpgrade; use oma_pm::matches::GetArchMethod; use oma_pm::matches::PackagesMatcher; - -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, info, warn}; use crate::HTTP_CLIENT; use crate::config::Config; diff --git a/src/subcommand/utils.rs b/src/subcommand/utils.rs index b6f6fd1f9..155ad0e29 100644 --- a/src/subcommand/utils.rs +++ b/src/subcommand/utils.rs @@ -79,10 +79,7 @@ use reqwest::Client; use std::fmt::Display; use super::remove::ask_user_do_as_i_say; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, error, info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, error, info, warn}; pub(crate) fn handle_no_result(no_result: Vec<&str>, no_progress: bool) -> Result<(), OutputError> { if no_result.is_empty() { diff --git a/src/utils.rs b/src/utils.rs index d32f59c17..3f90eb5c9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -31,10 +31,7 @@ use oma_utils::{ zbus::zvariant::OwnedFd, }; use rustix::process; -#[cfg(feature = "spdlog-rs")] use spdlog::{debug, info, warn}; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::{debug, info, warn}; type Result = std::result::Result; @@ -252,9 +249,6 @@ macro_rules! msg { ($($arg:tt)+) => { use oma_console::writer::Writeln as _; let s = format!($($arg)+); - #[cfg(not(feature = "spdlog-rs"))] - tracing::debug!("{s}"); - #[cfg(feature = "spdlog-rs")] spdlog::debug!("{s}"); $crate::WRITER.writeln("", &s).ok(); }; @@ -266,9 +260,6 @@ macro_rules! success { ($($arg:tt)+) => { use oma_console::writer::Writeln as _; let s = format!($($arg)+); - #[cfg(not(feature = "spdlog-rs"))] - tracing::debug!("{s}"); - #[cfg(feature = "spdlog-rs")] spdlog::debug!("{s}"); $crate::WRITER.writeln(&oma_console::console::style("SUCCESS").green().bold().to_string(), &s).ok(); }; @@ -280,9 +271,6 @@ macro_rules! due_to { ($($arg:tt)+) => { use oma_console::writer::Writeln as _; let s = format!($($arg)+); - #[cfg(not(feature = "spdlog-rs"))] - tracing::debug!("{s}"); - #[cfg(feature = "spdlog-rs")] spdlog::debug!("{s}"); $crate::WRITER.writeln(&oma_console::console::style("DUE TO").yellow().bold().to_string(), &s).ok(); }; From ce8b7fbfea8cf2a296a053d14b2f9f468da42895 Mon Sep 17 00:00:00 2001 From: Neko Date: Fri, 19 Sep 2025 15:57:44 +0800 Subject: [PATCH 3/9] refactor: update rotation policy for logger --- oma-pm/src/dpkg.rs | 2 +- src/config.rs | 1 - src/main.rs | 67 +++++++++++++++------------------------------- 3 files changed, 23 insertions(+), 47 deletions(-) diff --git a/oma-pm/src/dpkg.rs b/oma-pm/src/dpkg.rs index a7c30f103..0009ad55d 100644 --- a/oma-pm/src/dpkg.rs +++ b/oma-pm/src/dpkg.rs @@ -1,7 +1,7 @@ use std::{fmt::Display, fs, io, path::Path, str::FromStr}; use deb822_lossless::{Deb822, Paragraph}; -use tracing::{debug, info}; +use spdlog::{debug, info}; use crate::apt::{OmaAptError, OmaAptResult}; diff --git a/src/config.rs b/src/config.rs index d27b33402..2bac66800 100644 --- a/src/config.rs +++ b/src/config.rs @@ -206,7 +206,6 @@ impl Config { .unwrap_or_else(GeneralConfig::default_bell) } - #[allow(dead_code)] pub fn save_log_count(&self) -> usize { self.general .as_ref() diff --git a/src/main.rs b/src/main.rs index 5258ede33..7061079ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use std::env::{self, args}; use std::ffi::CString; -use std::fs::create_dir_all; use std::io::{self, IsTerminal, stderr, stdin}; use std::path::{Path, PathBuf}; @@ -8,7 +7,7 @@ use std::process::{Command, exit}; use std::sync::Arc; use std::sync::{LazyLock, OnceLock}; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use std::time::Duration; mod args; mod config; @@ -287,20 +286,21 @@ fn init_localizer() { fn init_logger( oma: &OhManagerAilurus, - _config: &Config, + config: &Config, ) -> (Option>, anyhow::Result) { let debug = oma.global.debug; let dry_run = oma.global.dry_run; - let log_dir = if is_root() { + let log_file = (if is_root() { PathBuf::from("/var/log/oma") } else { dirs::state_dir() .expect("Failed to get state dir") .join("oma") - }; - - let log_file = create_log_file(&log_dir); + }) + .join("oma.log") + .to_string_lossy() + .to_string(); let (level_filter, formatter) = if !debug && !dry_run { let level_filter = LevelFilter::MoreSevereEqual(Level::Info); @@ -319,24 +319,20 @@ fn init_logger( (level_filter, formatter) }; - let rotating_sink = if let Ok(log_file) = &log_file { - Some( - AsyncPoolSink::builder() - .sink(Arc::new( - RotatingFileSink::builder() - .base_path(&log_file) - .formatter(formatter.clone()) - .rotation_policy(RotationPolicy::Hourly) - .build() - .unwrap(), - )) - .overflow_policy(spdlog::sink::OverflowPolicy::DropIncoming) + let rotating_sink = AsyncPoolSink::builder() + .sink(Arc::new( + RotatingFileSink::builder() + .base_path(&log_file) + .formatter(formatter.clone()) + // 10 MB + .rotation_policy(RotationPolicy::FileSize(10 * 1024 * 1024)) + .max_files(config.save_log_count()) .build() .unwrap(), - ) - } else { - None - }; + )) + .overflow_policy(spdlog::sink::OverflowPolicy::DropIncoming) + .build() + .unwrap(); let stream_sink = StdStreamSink::builder() .formatter(formatter) @@ -348,33 +344,14 @@ fn init_logger( logger_builder .level_filter(level_filter) - .sink(Arc::new(stream_sink)); - - if let Some(rotating_sink) = rotating_sink { - logger_builder.sink(Arc::new(rotating_sink)); - } + .sink(Arc::new(stream_sink)) + .sink(Arc::new(rotating_sink)); let logger = logger_builder.build().unwrap(); set_default_logger(Arc::new(logger)); - (Some(default_logger()), log_file) -} - -fn create_log_file(log_dir: &Path) -> anyhow::Result { - create_dir_all(log_dir)?; - - let log_file = format!( - "oma.log.{}", - SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_secs() - ); - - let log_file = log_dir.join(log_file).to_string_lossy().to_string(); - - Ok(log_file) + (Some(default_logger()), Ok(log_file)) } #[inline] From 9167eeffdc2483922bdb987262aee8d76f010bb9 Mon Sep 17 00:00:00 2001 From: Neko Date: Fri, 3 Oct 2025 05:10:24 +0800 Subject: [PATCH 4/9] chore: upgrade to spdlog-rs 0.5.0 --- Cargo.lock | 39 +++++++++----------------------------- Cargo.toml | 9 +-------- apt-auth-config/Cargo.toml | 2 +- oma-console/Cargo.toml | 2 +- oma-contents/Cargo.toml | 2 +- oma-fetch/Cargo.toml | 2 +- oma-history/Cargo.toml | 2 +- oma-mirror/Cargo.toml | 2 +- oma-pm/Cargo.toml | 2 +- oma-refresh/Cargo.toml | 2 +- oma-repo-verify/Cargo.toml | 2 +- oma-topics/Cargo.toml | 2 +- oma-tum/Cargo.toml | 2 +- oma-utils/Cargo.toml | 2 +- 14 files changed, 22 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5333e4046..df2fbceaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2343,7 +2343,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ "hermit-abi", "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2854,15 +2854,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "nu-ansi-term" -version = "0.50.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" -dependencies = [ - "windows-sys 0.61.2", -] - [[package]] name = "num-bigint" version = "0.4.6" @@ -3006,8 +2997,6 @@ dependencies = [ "textwrap", "tokio", "toml 0.9.8", - "tracing", - "tracing-subscriber", ] [[package]] @@ -4443,7 +4432,8 @@ dependencies = [ [[package]] name = "spdlog-internal" version = "0.2.0" -source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=main-dev#eda51be20516ac54c78e87d27a040ec53fffc3a0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c4ffbdbc9f2d819ffb53ef00a253f524ba7bfd7a3aa8dcd50789b9b27be550" dependencies = [ "nom 8.0.0", "strum 0.27.2", @@ -4454,7 +4444,8 @@ dependencies = [ [[package]] name = "spdlog-macros" version = "0.3.0" -source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=main-dev#eda51be20516ac54c78e87d27a040ec53fffc3a0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b87a8a157696b61e2a87ed9753da2afb2a27c1e7490786fddf3e71d7e0c3b69e" dependencies = [ "proc-macro2", "quote", @@ -4464,8 +4455,9 @@ dependencies = [ [[package]] name = "spdlog-rs" -version = "0.5.1" -source = "git+https://github.com/SpriteOvO/spdlog-rs.git?branch=main-dev#eda51be20516ac54c78e87d27a040ec53fffc3a0" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d36fd7a0cb4b3f8fa5316a96d89bb68956a3db82427d2d96b9a93657caa0dcf" dependencies = [ "arc-swap", "atomic", @@ -4474,6 +4466,7 @@ dependencies = [ "dyn-clone", "is-terminal", "libc", + "log", "once_cell", "parking_lot", "rustc_version", @@ -5165,17 +5158,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - [[package]] name = "tracing-subscriber" version = "0.3.20" @@ -5183,15 +5165,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5" dependencies = [ "matchers", - "nu-ansi-term", "once_cell", "regex-automata", "sharded-slab", - "smallvec", "thread_local", "tracing", "tracing-core", - "tracing-log", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e66e7629f..1ce4376e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,14 +31,7 @@ chrono = "0.4.38" rustix = { version = "1", features = ["process", "stdio"] } libc = "0.2.159" reqwest = { version = "0.12.8", default-features = false } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev", features = [ - "multi-thread", - "source-location", -], optional = true } -tracing = { version = "0.1.40", optional = true } -tracing-subscriber = { version = "0.3.18", features = [ - "env-filter", -], optional = true } +spdlog-rs = { version = "0.5.0", features = ["multi-thread", "source-location", "log"] } console-subscriber = { version = "0.4.0", optional = true } ratatui = "0.29.0" ansi-to-tui = "7.0.0" diff --git a/apt-auth-config/Cargo.toml b/apt-auth-config/Cargo.toml index bbe329183..087f1e6ee 100644 --- a/apt-auth-config/Cargo.toml +++ b/apt-auth-config/Cargo.toml @@ -7,6 +7,6 @@ license = "MIT" [dependencies] thiserror = "2" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" rust-netrc = "0.1" url = "2.5" diff --git a/oma-console/Cargo.toml b/oma-console/Cargo.toml index 665666053..304450a39 100644 --- a/oma-console/Cargo.toml +++ b/oma-console/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT" chrono = { version = "0.4.38", optional = true } console = { version = "0.16", optional = true } indicatif = { version = "0.18", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" ratatui = { version = "0.29", optional = true } # https://github.com/async-rs/async-std/issues/1055 # https://github.com/tokio-rs/tokio/issues/5535 diff --git a/oma-contents/Cargo.toml b/oma-contents/Cargo.toml index 0aef71e7b..c08e820ea 100644 --- a/oma-contents/Cargo.toml +++ b/oma-contents/Cargo.toml @@ -14,7 +14,7 @@ winnow = "0.7" flate2 = "1.0" rayon = "1.8" lzzzz = "2.0" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" which = "8" zstd = "0.13" memchr = "2" diff --git a/oma-fetch/Cargo.toml b/oma-fetch/Cargo.toml index ca95f566a..ff834efec 100644 --- a/oma-fetch/Cargo.toml +++ b/oma-fetch/Cargo.toml @@ -20,7 +20,7 @@ async-compression = { version = "=0.4.27", features = ["gzip", "xz", "futures-io # even with older liblzma (Ubuntu 22.04 uses 5.2.x). Be mindful, however, that # async-compression depends on a different liblzma-rs than what is specified here. liblzma = { version = "0", features = ["uncheck_liblzma_version"] } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" tokio-util = { version = "0.7", features = ["compat"] } md-5 = "0.10.6" bon = "3" diff --git a/oma-history/Cargo.toml b/oma-history/Cargo.toml index 3c3e34b64..256ef5fd3 100644 --- a/oma-history/Cargo.toml +++ b/oma-history/Cargo.toml @@ -12,7 +12,7 @@ oma-pm-operation-type = { version = "0.9", path = "../oma-pm-operation-type" } rusqlite = { version = "0.37", features = ["bundled"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" thiserror = "2" [dev-dependencies] diff --git a/oma-mirror/Cargo.toml b/oma-mirror/Cargo.toml index 652be1e6b..d20ba18d0 100644 --- a/oma-mirror/Cargo.toml +++ b/oma-mirror/Cargo.toml @@ -11,6 +11,6 @@ serde_json = "1.0" snafu = "0.8.5" indexmap = { version = "2.6", features = ["serde"] } ahash = "0.8.11" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" once_cell = "1.19" toml = { version = "0.9", features = ["preserve_order"] } diff --git a/oma-pm/Cargo.toml b/oma-pm/Cargo.toml index 69c38426d..da847dbf9 100644 --- a/oma-pm/Cargo.toml +++ b/oma-pm/Cargo.toml @@ -24,7 +24,7 @@ tokio = { version = "1.15", default-features = false, features = [ "rt-multi-thread", ] } fs4 = "0.13" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" oma-pm-operation-type = { version = "0.9", path = "../oma-pm-operation-type" } zbus = { version = "5.1", features = ["tokio"] } cxx = "1.0.121" diff --git a/oma-refresh/Cargo.toml b/oma-refresh/Cargo.toml index 1f61be605..a83fabf16 100644 --- a/oma-refresh/Cargo.toml +++ b/oma-refresh/Cargo.toml @@ -16,7 +16,7 @@ futures = "0.3" oma-apt-sources-lists = "0.9" chrono = { version = "0.4", features = ["unstable-locales"] } oma-topics = { version = "^0.25.0", path = "../oma-topics", optional = true, default-features = false } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" oma-repo-verify = { version = "^0.9.0", path = "../oma-repo-verify", default-features = false } ahash = "0.8.11" oma-apt = { version = "0.11", optional = true } diff --git a/oma-repo-verify/Cargo.toml b/oma-repo-verify/Cargo.toml index 0f33b5f00..d6f05589d 100644 --- a/oma-repo-verify/Cargo.toml +++ b/oma-repo-verify/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" anyhow = "1" thiserror = "2" sequoia-openpgp = { version = "2", default-features = false } -spdlog-rs = { git = 'https://github.com/SpriteOvO/spdlog-rs.git', branch = "main-dev" } +spdlog-rs = "0.5.0" oma-apt-sources-lists = "0.9" sequoia-policy-config = "0.8" diff --git a/oma-topics/Cargo.toml b/oma-topics/Cargo.toml index 1fd07fcb5..328eda770 100644 --- a/oma-topics/Cargo.toml +++ b/oma-topics/Cargo.toml @@ -14,7 +14,7 @@ serde_json = "1.0" tokio = { version = "1.28", default-features = false, features = ["fs", "rt", "rt-multi-thread"] } thiserror = "2.0" futures = "0.3" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" url = "2.5" oma-mirror = { version = "0.7.0", path = "../oma-mirror" } ahash = "0.8.11" diff --git a/oma-tum/Cargo.toml b/oma-tum/Cargo.toml index 4161b5004..51bcfafb2 100644 --- a/oma-tum/Cargo.toml +++ b/oma-tum/Cargo.toml @@ -11,6 +11,6 @@ snafu = "0.8.6" serde = { version = "1", features = ["derive"] } serde_json = "1" ahash = "0.8.12" -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev" } +spdlog-rs = "0.5.0" logos = "0.15" debversion = "0.4.5" diff --git a/oma-utils/Cargo.toml b/oma-utils/Cargo.toml index a42bcd3de..8eb6061f6 100644 --- a/oma-utils/Cargo.toml +++ b/oma-utils/Cargo.toml @@ -13,7 +13,7 @@ number_prefix = { version = "0.4", optional = true } os-release = "0.1" zbus = { version = "5.1", optional = true } url-escape = { version = "0.1", optional = true } -spdlog-rs = { git = "https://github.com/SpriteOvO/spdlog-rs.git", branch = "main-dev"} +spdlog-rs = "0.5.0" logind-zbus = "5.1" [features] From 7fe3627e933a7c13c2f7ae782182e412d70f28f1 Mon Sep 17 00:00:00 2001 From: Neko Date: Fri, 3 Oct 2025 05:11:58 +0800 Subject: [PATCH 5/9] refactor: add log proxy, and with_kv field to OmaFormatter --- oma-console/src/print.rs | 25 ++++++++++++++++++------- src/main.rs | 11 +++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/oma-console/src/print.rs b/oma-console/src/print.rs index 9a9d59ada..900f28637 100644 --- a/oma-console/src/print.rs +++ b/oma-console/src/print.rs @@ -138,18 +138,20 @@ fn term_color(input: D, color: Action) -> StyledObject { /// /// # Example: /// ``` -/// use spdlog::{info, sink::StdStreamSink, Logger}; +/// use spdlog::{info, sink::StdStreamSink, Logger, Result}; /// use oma_console::OmaLayer; /// -/// let mut logger_builder = Logger::builder(); +/// fn main() -> Result<()> { +/// let mut logger_builder = Logger::builder(); /// -/// let logger = logger_builder.sink(Arc::new( -/// StdStreamSink::builder().formatter(Box::new(OmaLayer::default())).build().unwrap() -/// )).build().unwrap(); +/// let logger = logger_builder.sink(Arc::new( +/// StdStreamSink::builder().formatter(Box::new(OmaLayer::default())).build()? +/// )).build()?; /// -/// spdlog::set_default_logger(Arc::new(logger)); +/// spdlog::set_default_logger(Arc::new(logger)); /// -/// info!("My name is oma!"); +/// info!("My name is oma!"); +/// } /// ``` /// #[derive(Clone)] @@ -157,6 +159,8 @@ pub struct OmaFormatter { with_ansi: bool, with_time: bool, with_file: bool, + #[allow(unused)] + with_kv: bool, prefix_len: u16, } @@ -166,6 +170,7 @@ impl Default for OmaFormatter { with_ansi: true, with_file: false, with_time: false, + with_kv: false, prefix_len: 10, } } @@ -194,6 +199,12 @@ impl OmaFormatter { self } + #[allow(unused)] + pub fn with_kv(mut self, with_kv: bool) -> Self { + self.with_kv = with_kv; + self + } + fn format_impl( &self, record: &spdlog::Record, diff --git a/src/main.rs b/src/main.rs index 7061079ab..a857e2e58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,9 @@ use reqwest::Client; use rustix::stdio::stdout; // FIXME: `spdlog::error` is conflict with `mod error` use spdlog::{ - Level, LevelFilter, Logger, debug, default_logger, error as error2, info, set_default_logger, + Level, LevelFilter, Logger, debug, default_logger, info, init_log_crate_proxy, + prelude::error, + set_default_logger, sink::{AsyncPoolSink, RotatingFileSink, RotationPolicy, StdStreamSink}, warn, }; @@ -298,9 +300,9 @@ fn init_logger( .expect("Failed to get state dir") .join("oma") }) - .join("oma.log") - .to_string_lossy() - .to_string(); + .join("oma.log"); + + // TODO: We need `spdlog-rs` implements `EnvFilter` first let (level_filter, formatter) = if !debug && !dry_run { let level_filter = LevelFilter::MoreSevereEqual(Level::Info); @@ -350,6 +352,7 @@ fn init_logger( let logger = logger_builder.build().unwrap(); set_default_logger(Arc::new(logger)); + init_log_crate_proxy()?; (Some(default_logger()), Ok(log_file)) } From 373f2315e69b2aea5a0e6ff2d68964a1535719df Mon Sep 17 00:00:00 2001 From: Neko Date: Fri, 3 Oct 2025 05:35:06 +0800 Subject: [PATCH 6/9] refactor: simplify init_logger return type --- src/main.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index a857e2e58..d92dc3f2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,8 +39,8 @@ use reqwest::Client; use rustix::stdio::stdout; // FIXME: `spdlog::error` is conflict with `mod error` use spdlog::{ - Level, LevelFilter, Logger, debug, default_logger, info, init_log_crate_proxy, - prelude::error, + Level, LevelFilter, Logger, debug, info, init_log_crate_proxy, + prelude::error as error2, set_default_logger, sink::{AsyncPoolSink, RotatingFileSink, RotationPolicy, StdStreamSink}, warn, @@ -187,7 +187,7 @@ fn main() { console_subscriber::init(); #[cfg(not(feature = "tokio-console"))] - let (_guard, file) = init_logger(&oma, &config); + let file = init_logger(&oma, &config); debug!( "Run oma with args: {} (pid: {})", @@ -286,10 +286,7 @@ fn init_localizer() { LANGUAGE_LOADER.set_use_isolating(false); } -fn init_logger( - oma: &OhManagerAilurus, - config: &Config, -) -> (Option>, anyhow::Result) { +fn init_logger(oma: &OhManagerAilurus, config: &Config) -> anyhow::Result { let debug = oma.global.debug; let dry_run = oma.global.dry_run; @@ -352,9 +349,9 @@ fn init_logger( let logger = logger_builder.build().unwrap(); set_default_logger(Arc::new(logger)); - init_log_crate_proxy()?; + init_log_crate_proxy().unwrap(); - (Some(default_logger()), Ok(log_file)) + Ok(log_file.to_string_lossy().to_string()) } #[inline] From 1e5316a7f4be47ed0116ce6a219e727f40149200 Mon Sep 17 00:00:00 2001 From: Neko Date: Mon, 6 Oct 2025 01:28:39 +0800 Subject: [PATCH 7/9] fix: fix doc tests --- oma-console/src/print.rs | 15 +++++++++++---- src/tui/mod.rs | 3 --- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/oma-console/src/print.rs b/oma-console/src/print.rs index 900f28637..ff8ca9791 100644 --- a/oma-console/src/print.rs +++ b/oma-console/src/print.rs @@ -139,18 +139,25 @@ fn term_color(input: D, color: Action) -> StyledObject { /// # Example: /// ``` /// use spdlog::{info, sink::StdStreamSink, Logger, Result}; -/// use oma_console::OmaLayer; +/// use oma_console::OmaFormatter; +/// +/// use std::sync::Arc; /// /// fn main() -> Result<()> { /// let mut logger_builder = Logger::builder(); /// -/// let logger = logger_builder.sink(Arc::new( -/// StdStreamSink::builder().formatter(Box::new(OmaLayer::default())).build()? -/// )).build()?; +/// let stream_sink = StdStreamSink::builder() +/// .formatter(OmaFormatter::default()) +/// .stdout() +/// .build()?; +/// +/// let logger = logger_builder.sink(Arc::new(stream_sink)).build()?; /// /// spdlog::set_default_logger(Arc::new(logger)); /// /// info!("My name is oma!"); +/// +/// Ok(()) /// } /// ``` /// diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 222d12d9b..69b73be26 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -13,10 +13,7 @@ use oma_utils::{ dbus::{InhibitTypeUnion, take_wake_lock}, is_termux, }; -#[cfg(feature = "spdlog-rs")] use spdlog::info; -#[cfg(not(feature = "spdlog-rs"))] -use tracing::info; use tui_inner::{Task, Tui as TuiInner}; use crate::{ From 55e6fc98c3ecb136c59cd9198e320fa3bbea2384 Mon Sep 17 00:00:00 2001 From: Neko Date: Mon, 13 Oct 2025 18:37:19 +0800 Subject: [PATCH 8/9] fix: fix clippy --- oma-console/src/print.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oma-console/src/print.rs b/oma-console/src/print.rs index ff8ca9791..57b371eed 100644 --- a/oma-console/src/print.rs +++ b/oma-console/src/print.rs @@ -296,6 +296,6 @@ impl Formatter for OmaFormatter { ctx: &mut spdlog::formatter::FormatterContext, ) -> spdlog::Result<()> { self.format_impl(record, dest, ctx) - .map_err(|e| spdlog::Error::FormatRecord(e)) + .map_err(spdlog::Error::FormatRecord) } } From 438455386089b02dfd1db6d717a9849eb5e0b628 Mon Sep 17 00:00:00 2001 From: Neko Date: Tue, 14 Oct 2025 18:21:36 +0800 Subject: [PATCH 9/9] refactor: rename error2 to log_error --- src/main.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d92dc3f2d..18ecd4b98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,10 +37,9 @@ use oma_utils::dbus::{create_dbus_connection, get_another_oma_status}; use oma_utils::{OsRelease, is_termux}; use reqwest::Client; use rustix::stdio::stdout; -// FIXME: `spdlog::error` is conflict with `mod error` use spdlog::{ Level, LevelFilter, Logger, debug, info, init_log_crate_proxy, - prelude::error as error2, + prelude::error as log_error, set_default_logger, sink::{AsyncPoolSink, RotatingFileSink, RotationPolicy, StdStreamSink}, warn, @@ -380,7 +379,7 @@ fn try_main( if !plugin.is_file() { plugin = plugin_fallback; if !plugin.is_file() { - error2!("{}", fl!("custom-command-unknown", subcmd = subcommand)); + log_error!("{}", fl!("custom-command-unknown", subcmd = subcommand)); return Ok(1); } } @@ -393,7 +392,7 @@ fn try_main( let status = process.status().unwrap().code().unwrap(); if status != 0 { - error2!("{}", fl!("custom-command-applet-exception", s = status)); + log_error!("{}", fl!("custom-command-applet-exception", s = status)); } Ok(status) @@ -485,7 +484,7 @@ fn color_formatter() -> &'static OmaColorFormat { fn display_error_and_can_unlock(e: OutputError) -> io::Result { let mut unlock = true; if !e.description.is_empty() { - error2!("{e}"); + log_error!("{e}"); let cause = Chain::new(&e).skip(1).collect::>(); let last_cause = cause.last(); @@ -532,7 +531,7 @@ fn display_error_and_can_unlock(e: OutputError) -> io::Result { unlock = false; if let Err(e) = find_another_oma() { debug!("{e}"); - error2!("{}", fl!("failed-to-lock-oma")); + log_error!("{}", fl!("failed-to-lock-oma")); } } } @@ -555,7 +554,7 @@ async fn find_another_oma_inner() -> Result<(), OutputError> { pkg => fl!("status-package", pkg = pkg), }; - error2!("{}", fl!("another-oma-is-running", s = status)); + log_error!("{}", fl!("another-oma-is-running", s = status)); Ok(()) }