diff --git a/analysis/.rustfmt.toml b/analysis/.rustfmt.toml new file mode 100644 index 0000000..c809f4f --- /dev/null +++ b/analysis/.rustfmt.toml @@ -0,0 +1,7 @@ +hard_tabs = false +max_width = 100 +newline_style = "Unix" +reorder_imports = true +reorder_modules = true +tab_spaces = 2 +use_field_init_shorthand = true diff --git a/analysis/Cargo.lock b/analysis/Cargo.lock index e6f863b..0c41d90 100644 --- a/analysis/Cargo.lock +++ b/analysis/Cargo.lock @@ -17,6 +17,35 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -74,6 +103,60 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "cmta-fishnet" +version = "0.1.0" +dependencies = [ + "cmta-initializer", + "color-eyre", + "sentry", + "serde", + "serde_json", + "structopt", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "cmta-initializer" +version = "0.1.0" +dependencies = [ + "color-eyre", + "thiserror", + "tracing", + "tracing-attributes", + "tracing-subscriber", +] + +[[package]] +name = "cmta-telescope" +version = "0.1.0" +dependencies = [ + "cmta-initializer", + "color-eyre", + "sentry", + "serde", + "serde_json", + "thiserror", + "tracing", +] + [[package]] name = "color-eyre" version = "0.6.2" @@ -188,18 +271,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "fishnet" -version = "0.1.0" -dependencies = [ - "color-eyre", - "sentry", - "serde", - "serde_json", - "thiserror", - "tracing", -] - [[package]] name = "fnv" version = "1.0.7" @@ -320,6 +391,24 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.2" @@ -455,7 +544,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.2", "libc", "windows-sys", ] @@ -499,6 +588,16 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.19" @@ -511,6 +610,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.5.0" @@ -561,13 +669,23 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num_cpus" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.2", "libc", ] @@ -609,7 +727,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.23", ] [[package]] @@ -641,12 +759,41 @@ dependencies = [ "winapi", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owo-colors" version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + [[package]] name = "percent-encoding" version = "2.3.0" @@ -677,6 +824,30 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.63" @@ -736,18 +907,47 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.3.0", + "regex-syntax 0.7.3", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "regex-syntax", + "regex-syntax 0.6.29", ] +[[package]] +name = "regex-automata" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.3", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" [[package]] name = "reqwest" @@ -803,9 +1003,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.22" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8818fa822adcc98b18fedbb3632a6a33213c070556b5aa7c4c8cc21cff565c4c" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ "bitflags", "errno", @@ -830,6 +1030,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "security-framework" version = "2.9.1" @@ -984,7 +1190,7 @@ checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.23", ] [[package]] @@ -1019,6 +1225,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.8" @@ -1028,6 +1243,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + [[package]] name = "socket2" version = "0.4.9" @@ -1038,11 +1259,41 @@ dependencies = [ "winapi", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "syn" -version = "2.0.23" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -1050,15 +1301,14 @@ dependencies = [ ] [[package]] -name = "telescope" -version = "0.1.0" +name = "syn" +version = "2.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" dependencies = [ - "color-eyre", - "sentry", - "serde", - "serde_json", - "thiserror", - "tracing", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] @@ -1075,6 +1325,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.41" @@ -1092,7 +1351,7 @@ checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.23", ] [[package]] @@ -1159,11 +1418,25 @@ dependencies = [ "libc", "mio", "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", + "tokio-macros", "windows-sys", ] +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.23", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" @@ -1214,7 +1487,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.23", ] [[package]] @@ -1237,15 +1510,46 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "serde", + "serde_json", "sharded-slab", + "smallvec", "thread_local", + "tracing", "tracing-core", + "tracing-log", + "tracing-serde", ] [[package]] @@ -1284,6 +1588,18 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "ureq" version = "2.7.1" @@ -1331,6 +1647,18 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "want" version = "0.3.1" @@ -1367,7 +1695,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.23", "wasm-bindgen-shared", ] @@ -1401,7 +1729,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.23", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/analysis/Cargo.toml b/analysis/Cargo.toml index b00df50..4cf6067 100644 --- a/analysis/Cargo.toml +++ b/analysis/Cargo.toml @@ -1,5 +1,5 @@ [workspace] members = [ - "fishnet", - "telescope", + "bin/*", + "common/*" ] diff --git a/analysis/bin/fishnet/Cargo.toml b/analysis/bin/fishnet/Cargo.toml new file mode 100644 index 0000000..5ca2b2d --- /dev/null +++ b/analysis/bin/fishnet/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "cmta-fishnet" +version = "0.1.0" +edition = "2021" +authors = ["Darwinia Network "] +description = "Darwinia Community RPC" +repository = "https://github.com/dcdao/community-rpc" +license = "MIT" +homepage = "https://github.com/dcdao/community-rpc" +include = [ + "Cargo.toml", + "**/*.rs", + "README.md", + "LICENSE" +] +keywords = ["darwinia"] +readme = 'README.md' + +[dependencies] + +tracing = "0.1" +color-eyre = "0.6" +sentry = "0.31" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +thiserror = "1" +structopt = "0.3" +tokio = { version = "1", features = ["full"] } + + +cmta-initializer = { path = "../../common/initializer" } diff --git a/analysis/bin/fishnet/src/main.rs b/analysis/bin/fishnet/src/main.rs new file mode 100644 index 0000000..2599186 --- /dev/null +++ b/analysis/bin/fishnet/src/main.rs @@ -0,0 +1,9 @@ +mod types; + +#[tokio::main] +async fn main() -> color_eyre::Result<()> { + cmta_initializer::init()?; + println!("Hello, world!"); + tracing::debug!("Hello"); + Ok(()) +} diff --git a/analysis/bin/fishnet/src/types/command.rs b/analysis/bin/fishnet/src/types/command.rs new file mode 100644 index 0000000..f05f9b3 --- /dev/null +++ b/analysis/bin/fishnet/src/types/command.rs @@ -0,0 +1 @@ +// pub struct diff --git a/analysis/bin/fishnet/src/types/mod.rs b/analysis/bin/fishnet/src/types/mod.rs new file mode 100644 index 0000000..9fe7961 --- /dev/null +++ b/analysis/bin/fishnet/src/types/mod.rs @@ -0,0 +1 @@ +pub mod command; diff --git a/analysis/fishnet/Cargo.toml b/analysis/bin/telescope/Cargo.toml similarity index 86% rename from analysis/fishnet/Cargo.toml rename to analysis/bin/telescope/Cargo.toml index 3a3750a..7e2b9fc 100644 --- a/analysis/fishnet/Cargo.toml +++ b/analysis/bin/telescope/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "fishnet" +name = "cmta-telescope" version = "0.1.0" edition = "2021" authors = ["Darwinia Network "] @@ -25,3 +25,6 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" thiserror = "1" + +cmta-initializer = { path = "../../common/initializer" } + diff --git a/analysis/fishnet/src/main.rs b/analysis/bin/telescope/src/main.rs similarity index 100% rename from analysis/fishnet/src/main.rs rename to analysis/bin/telescope/src/main.rs diff --git a/analysis/telescope/Cargo.toml b/analysis/common/initializer/Cargo.toml similarity index 66% rename from analysis/telescope/Cargo.toml rename to analysis/common/initializer/Cargo.toml index e652507..35829d6 100644 --- a/analysis/telescope/Cargo.toml +++ b/analysis/common/initializer/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "telescope" +name = "cmta-initializer" version = "0.1.0" edition = "2021" authors = ["Darwinia Network "] @@ -18,10 +18,10 @@ readme = 'README.md' [dependencies] -tracing = "0.1" -color-eyre = "0.6" -sentry = "0.31" -serde = { version = "1", features = ["derive"] } -serde_json = "1" -thiserror = "1" +color-eyre = "0.6" +thiserror = "1" + +tracing = "0.1" +tracing-attributes = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json"] } diff --git a/analysis/common/initializer/src/error.rs b/analysis/common/initializer/src/error.rs new file mode 100644 index 0000000..970de65 --- /dev/null +++ b/analysis/common/initializer/src/error.rs @@ -0,0 +1,8 @@ +use thiserror::Error as ThisError; + +/// Ethereum component error +#[derive(ThisError, Debug)] +pub enum InitializerError { + #[error("Custom: {0}")] + Custom(String), +} diff --git a/analysis/common/initializer/src/init_log.rs b/analysis/common/initializer/src/init_log.rs new file mode 100644 index 0000000..a49c3fa --- /dev/null +++ b/analysis/common/initializer/src/init_log.rs @@ -0,0 +1,49 @@ +use std::str::FromStr; + +use tracing::Level; + +// use tracing_subscriber::fmt::time::SystemTime; +use tracing_subscriber::EnvFilter; + +use crate::error::InitializerError; + +pub fn init_log() -> Result<(), InitializerError> { + color_eyre::install().map_err(|e| InitializerError::Custom(format!("{:?}", e)))?; + // if std::env::var("RUST_BACKTRACE").is_err() { + // std::env::set_var("RUST_SPANTRACE", "1"); + // std::env::set_var("RUST_LIB_BACKTRACE", "full"); + // } + + let def_log_filter = ["info", "cmta_fishnet=trace", "cmta_telescope=trace"].join(","); + + let use_json_adapter = std::env::var("LOG_ADAPTER") + .map(|v| &v.to_lowercase()[..] == "json") + .unwrap_or_default(); + let max_log_level = std::env::var("LOG_MAX_LEVEL") + .map(|v| Level::from_str(&v).unwrap_or(Level::TRACE)) + .unwrap_or(Level::TRACE); + + if use_json_adapter { + tracing_subscriber::FmtSubscriber::builder() + .with_max_level(max_log_level) + .with_env_filter( + EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::from(def_log_filter)), + ) + .json() + .init(); + // tracing::subscriber::set_global_default(subscriber) + // .expect("setting default subscriber failed"); + return Ok(()); + } + + tracing_subscriber::FmtSubscriber::builder() + .with_max_level(max_log_level) + .with_env_filter( + EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::from(def_log_filter)), + ) + // https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html + .with_timer(tracing_subscriber::fmt::time::time()) + .init(); + // tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); + Ok(()) +} diff --git a/analysis/common/initializer/src/lib.rs b/analysis/common/initializer/src/lib.rs new file mode 100644 index 0000000..3ec7204 --- /dev/null +++ b/analysis/common/initializer/src/lib.rs @@ -0,0 +1,10 @@ +use crate::error::InitializerError; + +mod init_log; + +pub mod error; + +pub fn init() -> Result<(), InitializerError> { + init_log::init_log()?; + Ok(()) +} diff --git a/analysis/telescope/src/main.rs b/analysis/telescope/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/analysis/telescope/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}