From 7abdf00db48023fe3bf1b853784702d6536f10e5 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 23 Oct 2021 17:45:36 +0200 Subject: [PATCH] Add tracing output instead of log Signed-off-by: trivernis --- mediarepo-daemon/Cargo.lock | 200 ++++++++------------ mediarepo-daemon/Cargo.toml | 27 ++- mediarepo-daemon/logs/db_traces.logs | 78 ++++++++ mediarepo-daemon/mediarepo-model/src/tag.rs | 3 + mediarepo-daemon/src/logging.rs | 24 +++ mediarepo-daemon/src/main.rs | 59 ++---- 6 files changed, 226 insertions(+), 165 deletions(-) create mode 100644 mediarepo-daemon/logs/db_traces.logs create mode 100644 mediarepo-daemon/src/logging.rs diff --git a/mediarepo-daemon/Cargo.lock b/mediarepo-daemon/Cargo.lock index 6eea433..140964b 100644 --- a/mediarepo-daemon/Cargo.lock +++ b/mediarepo-daemon/Cargo.lock @@ -16,24 +16,15 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "ahash" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ "getrandom", "once_cell", "version_check", ] -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - [[package]] name = "ansi_term" version = "0.11.0" @@ -183,9 +174,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcd555c66291d5f836dbb6883b48660ece810fe25a31f3bdfb911945dff2691f" +checksum = "2607a74355ce2e252d0c483b2d8a348e1bba36036e786ccc2dcd777213c86ffd" dependencies = [ "arrayref", "arrayvec 0.7.1", @@ -212,9 +203,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "bumpalo" -version = "3.7.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" +checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" [[package]] name = "bytemuck" @@ -236,9 +227,9 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" [[package]] name = "cfg-if" @@ -262,7 +253,7 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time", + "time 0.1.44", "winapi", ] @@ -301,9 +292,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "core-foundation" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" dependencies = [ "core-foundation-sys", "libc", @@ -311,9 +302,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" @@ -470,19 +461,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "foreign-types" version = "0.3.2" @@ -698,15 +676,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "idna" version = "0.2.3" @@ -749,9 +718,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if 1.0.0", ] @@ -803,9 +772,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.103" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" [[package]] name = "libsqlite3-sys" @@ -860,12 +829,13 @@ dependencies = [ "mediarepo-core", "mediarepo-model", "mediarepo-socket", - "pretty_env_logger", "structopt", "tokio", "toml", + "tracing", + "tracing-appender", "tracing-flame", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -984,9 +954,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", "log", @@ -1256,9 +1226,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" +checksum = "10e2fcbb64ecbe64c8e040a386c3104d384583af58b956d870aaaf229df6e66d" [[package]] name = "png" @@ -1274,19 +1244,9 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - -[[package]] -name = "pretty_env_logger" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" -dependencies = [ - "env_logger", - "log", -] +checksum = "c3ca011bd0129ff4ae15cd04c4eef202cadf6c51c21e47aba319b4e0501db741" [[package]] name = "proc-macro-crate" @@ -1362,19 +1322,13 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70" dependencies = [ "unicode-xid", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.10" @@ -1464,8 +1418,6 @@ version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ - "aho-corasick", - "memchr", "regex-syntax", ] @@ -1531,9 +1483,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f1028de22e436bb35fce070310ee57d57b5e59ae77b4e3f24ce4773312b813" +checksum = "353775f96a1f400edcca737f843cb201af3645912e741e64456a257c770173e8" dependencies = [ "arrayvec 0.5.2", "num-traits", @@ -1570,9 +1522,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sea-orm" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e715900921a367b557c9f5b5b5f554f514130d104c5ec1b555dfccc0e11a90e8" +checksum = "c3c5c7f0848ed7ddb2b3956abc84d5167dd33bb34c43e3b69172f565ca657a11" dependencies = [ "async-stream", "async-trait", @@ -1591,9 +1543,9 @@ dependencies = [ [[package]] name = "sea-orm-macros" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b6f4cdd6d918845980bd3572f55f95d9c79a9c2352192f33bca99d91ca350a" +checksum = "9466819cb0878e7fb6f6a1d7e46471a93b7121fef39db82f5799127884e39534" dependencies = [ "bae", "convert_case", @@ -1605,9 +1557,9 @@ dependencies = [ [[package]] name = "sea-query" -version = "0.16.5" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "365da31fb7b9b77aaf655797a0e60cfb18121906c03779558035e8fd4c6be2c2" +checksum = "17002e169ec19c435d33ebfbc25aa8d7381c2410cc2e27e556be837ec5546586" dependencies = [ "chrono", "rust_decimal", @@ -1741,9 +1693,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smallvec" @@ -1870,9 +1822,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.23" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa" +checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" dependencies = [ "clap", "lazy_static", @@ -1881,9 +1833,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.16" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck", "proc-macro-error 1.0.4", @@ -1894,9 +1846,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.78" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4eac2e6c19f5c3abc0c229bea31ff0b9b091c7b14990e8924b92902a303a0c0" +checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" dependencies = [ "proc-macro2", "quote", @@ -1916,9 +1868,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.5" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "474aaa926faa1603c40b7885a9eaea29b444d1cb2850cb7c0e37bb1a4182f4fa" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", @@ -1940,15 +1892,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "termcolor" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" -dependencies = [ - "winapi-util", -] - [[package]] name = "textwrap" version = "0.11.0" @@ -2009,6 +1952,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "time" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde1cf55178e0293453ba2cca0d5f8392a922e52aa958aee9c28ed02becc6d03" +dependencies = [ + "itoa", + "libc", +] + [[package]] name = "tinyvec" version = "1.5.0" @@ -2053,9 +2006,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" +checksum = "b2dd85aeaba7b68df939bd357c6afb36c87951be9e80bf9c859f2fc3e9fca0fd" dependencies = [ "proc-macro2", "quote", @@ -2104,6 +2057,17 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94571df2eae3ed4353815ea5a90974a594a1792d8782ff2cbcc9392d1101f366" +dependencies = [ + "crossbeam-channel", + "time 0.3.3", + "tracing-subscriber 0.3.0", +] + [[package]] name = "tracing-attributes" version = "0.1.18" @@ -2132,7 +2096,7 @@ checksum = "bd520fe41c667b437952383f3a1ec14f1fa45d653f719a77eedd6e6a02d8fa54" dependencies = [ "lazy_static", "tracing", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -2189,6 +2153,17 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "tracing-subscriber" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cf865b5ddc38e503a29c41c4843e616a73028ae18c637bc3eb2afaef4909c84" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + [[package]] name = "typemap_rev" version = "0.1.5" @@ -2212,9 +2187,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" @@ -2397,15 +2372,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/mediarepo-daemon/Cargo.toml b/mediarepo-daemon/Cargo.toml index 0525002..56bb622 100644 --- a/mediarepo-daemon/Cargo.toml +++ b/mediarepo-daemon/Cargo.toml @@ -15,13 +15,14 @@ name = "mediarepo" crate-type = ["lib"] [dependencies] +tracing = "0.1.29" toml = {version = "0.5.8", optional=true} structopt = {version="0.3.23", optional=true} -pretty_env_logger = {version="0.4.0", optional=true} glob = {version="0.3.0", optional=true} -log = "0.4.14" -tracing-flame = "0.1.0" -tracing-subscriber = "0.2.3" +log = {version="0.4.14", optional=true} +tracing-flame = {version = "0.1.0", optional=true} +tracing-appender = {version="0.2.0", optional=true} + [dependencies.mediarepo-core] path = "./mediarepo-core" @@ -38,7 +39,23 @@ optional=true version = "1.12.0" features = ["macros", "rt-multi-thread", "io-std", "io-util"] +[dependencies.tracing-subscriber] +version="0.2.3" +optional=true +features = ["env-filter"] + + [features] default = ["runtime"] -runtime = ["toml", "structopt", "mediarepo-model", "mediarepo-socket", "pretty_env_logger", "glob"] +runtime = [ + "toml", + "structopt", + "mediarepo-model", + "mediarepo-socket", + "tracing-subscriber", + "log", + "glob", + "tracing-flame", + "tracing-appender" +] library = ["mediarepo-socket"] \ No newline at end of file diff --git a/mediarepo-daemon/logs/db_traces.logs b/mediarepo-daemon/logs/db_traces.logs new file mode 100644 index 0000000..f0a05af --- /dev/null +++ b/mediarepo-daemon/logs/db_traces.logs @@ -0,0 +1,78 @@ +2021-10-23T15:44:21.613898807+02:00 - PRAGMA page_size = 4096; …; rows: 2, elapsed: 425.678µs + +PRAGMA page_size = 4096; +PRAGMA locking_mode = NORMAL; +PRAGMA journal_mode = WAL; +PRAGMA foreign_keys = ON; +PRAGMA synchronous = FULL; +PRAGMA auto_vacuum = NONE; + +2021-10-23T15:44:21.614073278+02:00 - CREATE TABLE IF NOT …; rows: 0, elapsed: 40.557µs + +CREATE TABLE IF NOT EXISTS _sqlx_migrations ( + version BIGINT PRIMARY KEY, + description TEXT NOT NULL, + installed_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + success BOOLEAN NOT NULL, + checksum BLOB NOT NULL, + execution_time BIGINT NOT NULL +); + +2021-10-23T15:44:21.614185925+02:00 - SELECT version FROM _sqlx_migrations …; rows: 0, elapsed: 66.197µs + +SELECT + version +FROM + _sqlx_migrations +WHERE + success = false +ORDER BY + version +LIMIT + 1 + +2021-10-23T15:44:21.614324891+02:00 - SELECT version, checksum FROM …; rows: 7, elapsed: 81.895µs + +SELECT + version, + checksum +FROM + _sqlx_migrations +ORDER BY + version + +2021-10-23T15:44:21.614983465+02:00 - PRAGMA page_size = 4096; …; rows: 2, elapsed: 309.278µs + +PRAGMA page_size = 4096; +PRAGMA locking_mode = NORMAL; +PRAGMA journal_mode = WAL; +PRAGMA foreign_keys = ON; +PRAGMA synchronous = FULL; +PRAGMA auto_vacuum = NONE; + +2021-10-23T15:44:21.615170159+02:00 - SELECT `storage_locations`.`id`, `storage_locations`.`name`, `storage_locations`.`path` …; rows: 1, elapsed: 85.937µs + +SELECT + `storage_locations`.`id`, + `storage_locations`.`name`, + `storage_locations`.`path` +FROM + `storage_locations` +WHERE + `storage_locations`.`path` = ? +LIMIT + ? + +2021-10-23T15:44:21.615322919+02:00 - SELECT `storage_locations`.`id`, `storage_locations`.`name`, `storage_locations`.`path` …; rows: 1, elapsed: 38.929µs + +SELECT + `storage_locations`.`id`, + `storage_locations`.`name`, + `storage_locations`.`path` +FROM + `storage_locations` +WHERE + `storage_locations`.`path` = ? +LIMIT + ? + diff --git a/mediarepo-daemon/mediarepo-model/src/tag.rs b/mediarepo-daemon/mediarepo-model/src/tag.rs index 634a577..5c7f8bc 100644 --- a/mediarepo-daemon/mediarepo-model/src/tag.rs +++ b/mediarepo-daemon/mediarepo-model/src/tag.rs @@ -73,6 +73,9 @@ impl Tag { db: DatabaseConnection, namespaces_with_names: Vec<(Option, String)>, ) -> RepoResult> { + if namespaces_with_names.is_empty() { + return Ok(Vec::new()); + } let mut or_condition = Condition::any(); for (namespace, name) in namespaces_with_names { diff --git a/mediarepo-daemon/src/logging.rs b/mediarepo-daemon/src/logging.rs new file mode 100644 index 0000000..557eb1f --- /dev/null +++ b/mediarepo-daemon/src/logging.rs @@ -0,0 +1,24 @@ +use tracing_flame::FlameLayer; +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{fmt, EnvFilter}; + +pub fn init_tracing() { + fmt::SubscriberBuilder::default() + .with_env_filter(EnvFilter::from_default_env()) + .with_writer(std::io::stdout) + .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) + .compact() + .init(); +} + +pub fn init_tracing_flame() -> impl Drop { + let fmt_layer = fmt::Layer::default(); + let (flame_layer, _guard) = FlameLayer::with_file("./tracing.folded").unwrap(); + tracing_subscriber::registry() + .with(fmt_layer) + .with(flame_layer) + .init(); + _guard +} diff --git a/mediarepo-daemon/src/main.rs b/mediarepo-daemon/src/main.rs index 14f6485..403eb4d 100644 --- a/mediarepo-daemon/src/main.rs +++ b/mediarepo-daemon/src/main.rs @@ -1,9 +1,11 @@ -mod constants; -mod utils; +use std::path::PathBuf; +use std::sync::Arc; + +use structopt::StructOpt; +use tokio::fs; +use tokio::runtime; +use tokio::runtime::Runtime; -use crate::constants::{DEFAULT_STORAGE_NAME, SETTINGS_PATH, THUMBNAIL_STORAGE_NAME}; -use crate::utils::{create_paths_for_repo, get_repo, load_settings}; -use log::LevelFilter; use mediarepo_core::error::RepoResult; use mediarepo_core::settings::Settings; use mediarepo_core::type_keys::SettingsKey; @@ -12,17 +14,13 @@ use mediarepo_model::file::File as RepoFile; use mediarepo_model::repo::Repo; use mediarepo_model::type_keys::RepoKey; use mediarepo_socket::get_builder; -use pretty_env_logger::env_logger::WriteStyle; -use std::env; -use std::path::PathBuf; -use std::str::FromStr; -use std::sync::Arc; -use structopt::StructOpt; -use tokio::fs; -use tokio::runtime; -use tokio::runtime::Runtime; -use tracing_flame::FlameLayer; -use tracing_subscriber::{fmt, prelude::*}; + +use crate::constants::{DEFAULT_STORAGE_NAME, SETTINGS_PATH, THUMBNAIL_STORAGE_NAME}; +use crate::utils::{create_paths_for_repo, get_repo, load_settings}; + +mod constants; +mod logging; +mod utils; #[derive(Debug, StructOpt)] #[structopt(name = "mediarepo", about = "A multimedia repository")] @@ -64,9 +62,9 @@ fn main() -> RepoResult<()> { let opt: Opt = Opt::from_args(); let mut _guard = None; if opt.profile { - _guard = Some(init_tracing_flame()); + _guard = Some(logging::init_tracing_flame()); } else { - build_logger(); + logging::init_tracing(); } match opt.cmd.clone() { @@ -97,31 +95,6 @@ fn get_multi_thread_runtime() -> Runtime { .unwrap() } -fn build_logger() { - pretty_env_logger::formatted_timed_builder() - .filter( - None, - env::var("RUST_LOG") - .ok() - .and_then(|level| LevelFilter::from_str(&level).ok()) - .unwrap_or(LevelFilter::Info), - ) - .write_style(WriteStyle::Always) - .filter_module("sqlx", log::LevelFilter::Warn) - .filter_module("tokio", log::LevelFilter::Info) - .init(); -} - -fn init_tracing_flame() -> impl Drop { - let fmt_layer = fmt::Layer::default(); - let (flame_layer, _guard) = FlameLayer::with_file("./tracing.folded").unwrap(); - tracing_subscriber::registry() - .with(fmt_layer) - .with(flame_layer) - .init(); - _guard -} - async fn init_repo(opt: &Opt) -> RepoResult<(Settings, Repo)> { let settings = load_settings(&opt.repo.join(SETTINGS_PATH)).await?; let mut repo = get_repo(&opt.repo.join(&settings.database_path).to_str().unwrap()).await?;