From 4e8728bfc2498fc2faba13df45fdf83eca68bf51 Mon Sep 17 00:00:00 2001 From: Tom Kirchner Date: Mon, 28 Oct 2019 10:59:08 -0700 Subject: [PATCH 1/2] Use `simplelog` to get errors on stderr, others on stdout --- packages/workspaces/apiserver.service | 2 +- packages/workspaces/migrator.service | 2 +- workspaces/Cargo.lock | 193 ++++++------------ workspaces/api/apiserver/Cargo.toml | 4 +- workspaces/api/apiserver/src/bin/apiserver.rs | 48 ++--- workspaces/api/apiserver/src/lib.rs | 2 +- workspaces/api/data_store_version/Cargo.toml | 2 +- workspaces/api/data_store_version/src/lib.rs | 2 +- workspaces/api/host-containers/Cargo.toml | 4 +- workspaces/api/host-containers/src/main.rs | 53 +++-- workspaces/api/migration/migrator/Cargo.toml | 4 +- workspaces/api/migration/migrator/src/args.rs | 21 +- .../api/migration/migrator/src/error.rs | 8 +- workspaces/api/migration/migrator/src/main.rs | 23 +-- workspaces/api/moondog/Cargo.toml | 4 +- workspaces/api/moondog/src/main.rs | 49 ++--- workspaces/api/pluto/Cargo.toml | 2 - workspaces/api/servicedog/Cargo.toml | 4 +- workspaces/api/servicedog/src/main.rs | 53 +++-- workspaces/api/settings-committer/Cargo.toml | 4 +- workspaces/api/settings-committer/src/main.rs | 53 +++-- workspaces/api/storewolf/Cargo.toml | 4 +- workspaces/api/storewolf/src/main.rs | 51 ++--- workspaces/api/sundog/Cargo.toml | 4 +- workspaces/api/sundog/src/main.rs | 53 +++-- workspaces/api/thar-be-settings/Cargo.toml | 4 +- workspaces/api/thar-be-settings/src/error.rs | 5 - workspaces/api/thar-be-settings/src/lib.rs | 2 +- workspaces/api/thar-be-settings/src/main.rs | 46 ++--- workspaces/updater/updog/Cargo.toml | 4 +- workspaces/updater/updog/src/error.rs | 8 +- workspaces/updater/updog/src/main.rs | 48 +++-- workspaces/webpki-roots-shim/Cargo.toml | 2 +- workspaces/webpki-roots-shim/src/lib.rs | 9 +- 34 files changed, 329 insertions(+), 448 deletions(-) diff --git a/packages/workspaces/apiserver.service b/packages/workspaces/apiserver.service index e3d0c4302aa..f5c9802e658 100644 --- a/packages/workspaces/apiserver.service +++ b/packages/workspaces/apiserver.service @@ -5,7 +5,7 @@ Requires=storewolf.service migrator.service [Service] Type=notify -ExecStart=/usr/bin/apiserver --datastore-path /var/lib/thar/datastore/current --socket-gid 274 -v -v -v +ExecStart=/usr/bin/apiserver --datastore-path /var/lib/thar/datastore/current --socket-gid 274 [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/migrator.service b/packages/workspaces/migrator.service index 8b393305f16..9d1ed9fd817 100644 --- a/packages/workspaces/migrator.service +++ b/packages/workspaces/migrator.service @@ -3,7 +3,7 @@ Description=Thar data store migrator [Service] Type=oneshot -ExecStart=/usr/bin/migrator --datastore-path /var/lib/thar/datastore/current --migration-directories /var/lib/thar/datastore/migrations --migrate-to-version-from-file /usr/share/thar/data-store-version -v -v +ExecStart=/usr/bin/migrator --datastore-path /var/lib/thar/datastore/current --migration-directories /var/lib/thar/datastore/migrations --migrate-to-version-from-file /usr/share/thar/data-store-version RemainAfterExit=true [Install] diff --git a/workspaces/Cargo.lock b/workspaces/Cargo.lock index 218081edc81..fe4a300eab6 100644 --- a/workspaces/Cargo.lock +++ b/workspaces/Cargo.lock @@ -275,16 +275,16 @@ dependencies = [ "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "systemd 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -672,9 +672,9 @@ version = "0.1.0" dependencies = [ "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -708,6 +708,26 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dirs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dirs-sys" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dns-lookup" version = "1.0.1" @@ -1047,11 +1067,11 @@ dependencies = [ "apiserver 0.1.0", "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1260,9 +1280,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "libc" @@ -1340,14 +1357,6 @@ name = "maplit" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "matchers" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "matches" version = "0.1.8" @@ -1396,12 +1405,12 @@ dependencies = [ "data_store_version 0.1.0", "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1492,13 +1501,13 @@ dependencies = [ "apiserver 0.1.0", "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1660,14 +1669,6 @@ dependencies = [ "vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "owning_ref" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot" version = "0.9.0" @@ -1765,8 +1766,6 @@ dependencies = [ "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2053,16 +2052,6 @@ dependencies = [ "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex-automata" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex-syntax" version = "0.6.12" @@ -2367,11 +2356,11 @@ dependencies = [ "apiserver 0.1.0", "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2381,11 +2370,11 @@ dependencies = [ "apiclient 0.1.0", "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2451,6 +2440,16 @@ dependencies = [ "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "simplelog" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "skeptic" version = "0.13.4" @@ -2517,11 +2516,6 @@ name = "spin" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "stable_deref_trait" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "storewolf" version = "0.1.0" @@ -2529,11 +2523,11 @@ dependencies = [ "apiserver 0.1.0", "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "data_store_version 0.1.0", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2583,11 +2577,11 @@ dependencies = [ "apiserver 0.1.0", "cargo-readme 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2665,6 +2659,15 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "term" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -2684,12 +2687,12 @@ dependencies = [ "handlebars 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2993,61 +2996,6 @@ dependencies = [ "untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tracing" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-attributes 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-core" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-log" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-subscriber" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "matchers 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-log 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "trust-dns-proto" version = "0.7.4" @@ -3197,6 +3145,7 @@ version = "0.1.0" dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "data_store_version 0.1.0", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lz4 1.23.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3205,12 +3154,11 @@ dependencies = [ "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "serde_plain 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "signpost 0.1.0", + "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "tough 0.1.0", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3238,11 +3186,6 @@ name = "utf8-cstr" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "utf8-ranges" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "uuid" version = "0.7.4" @@ -3386,8 +3329,8 @@ name = "webpki-roots" version = "0.17.0" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "pem 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3534,6 +3477,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +"checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" +"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" "checksum dns-lookup 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13988670860b076248c74e1b54444efc4f1dec70c8bb25da4b7c0024396b72bf" "checksum doc-comment 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "923dea538cea0aa3025e8685b20d6ee21ef99c4f77e954a30febbaac5ec73a97" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" @@ -3603,7 +3548,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lz4 1.23.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43c94a9f09a60017f373020cc93d4291db4cd92b0db64ff25927f27d09dc23d5" "checksum lz4-sys 1.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "20ab022822e9331c58d373acdd6b98085bace058ac6837b8266f213a2fccdafe" "checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" -"checksum matchers 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum md5 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e6bcd6433cff03a4bfc3d9834d504467db1f1cf6d0ea765d37d330249ed629d" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" @@ -3631,7 +3575,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-src 111.6.0+1.1.1d (registry+https://github.com/rust-lang/crates.io-index)" = "b9c2da1de8a7a3f860919c01540b03a6db16de042405a8a07a5e9d0b4b825d9c" "checksum openssl-sys 0.9.51 (registry+https://github.com/rust-lang/crates.io-index)" = "ba24190c8f0805d3bd2ce028f439fe5af1d55882bbe6261bed1dbc93b50dd6b1" -"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" "checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum pem 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39eb474073dfddbf7156515344266245d91ce698ddbf15e0498cef22b836f45a" @@ -3673,7 +3616,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d" "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" -"checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650" @@ -3707,6 +3649,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" "checksum signal-hook 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4f61c4d59f3aaa9f61bba6450a9b80ba48362fd7d651689e7a10c453b1f6dc68" "checksum signal-hook-registry 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1797d48f38f91643908bb14e35e79928f9f4b3cefb2420a564dde0991b4358dc" +"checksum simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "05a3e303ace6adb0a60a9e9e2fbc6a33e1749d1e43587e2125f7efa9c5e107c5" "checksum skeptic 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fb8ed853fdc19ce09752d63f3a2e5b5158aeb261520cd75eb618bd60305165" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" @@ -3715,7 +3658,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum structopt 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4f66a4c0ddf7aee4677995697366de0749b0139057342eccbb609b12d0affc" @@ -3728,6 +3670,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum systemd 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "daf2fd2d346d2dfb5fdc5f47b355f60dcfc35f5ee3e89e64e7ae2849ec8792a5" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +"checksum term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" @@ -3751,11 +3694,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" "checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" "checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724" -"checksum tracing 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c21ff9457accc293386c20e8f754d0b059e67e325edf2284f04230d125d7e5ff" -"checksum tracing-attributes 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3ff978fd9c9afe2cc9c671e247713421c6406b3422305cbdce5de695d3ab4c3c" -"checksum tracing-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "528c8ebaaa16cdac34795180b046c031775b0d56402704d98c096788f33d646a" -"checksum tracing-log 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc99e1286541d6ccc42d5fb37213d1cdde544f88b19fac3d94e3117b55163" -"checksum tracing-subscriber 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "63e6bb522a99f10b3b0b3b894f936bccc2516cc8761e5506de132b06bf8d2e4d" "checksum trust-dns-proto 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5559ebdf6c2368ddd11e20b11d6bbaf9e46deb803acd7815e93f5a7b4a6d2901" "checksum trust-dns-resolver 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c9992e58dba365798803c0b91018ff6c8d3fc77e06977c4539af2a6bfe0a039" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" @@ -3773,7 +3711,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" "checksum utf8-cstr 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "55bcbb425141152b10d5693095950b51c3745d019363fc2929ffd8f61449b628" -"checksum utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" "checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" diff --git a/workspaces/api/apiserver/Cargo.toml b/workspaces/api/apiserver/Cargo.toml index b08b28cd766..e7c08a44c41 100644 --- a/workspaces/api/apiserver/Cargo.toml +++ b/workspaces/api/apiserver/Cargo.toml @@ -10,12 +10,12 @@ build = "build.rs" actix-web = { version = "1.0.5", default-features = false, features = ["uds"] } base64 = "0.10" lazy_static = "1.2" -tracing = "0.1" +log = "0.4" regex = "1.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" toml = "0.5" walkdir = "2.2" systemd = { version = "0.4.0", default-features = false, features = [], optional = true } diff --git a/workspaces/api/apiserver/src/bin/apiserver.rs b/workspaces/api/apiserver/src/bin/apiserver.rs index f34080bb3ad..4565a4c3434 100644 --- a/workspaces/api/apiserver/src/bin/apiserver.rs +++ b/workspaces/api/apiserver/src/bin/apiserver.rs @@ -3,18 +3,16 @@ #![deny(rust_2018_idioms)] #[macro_use] -extern crate tracing; +extern crate log; use libc::gid_t; use nix::unistd::Gid; +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{ensure, ResultExt}; use std::env; use std::path::Path; use std::process; -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; +use std::str::FromStr; use apiserver::serve; @@ -34,19 +32,17 @@ mod error { #[snafu(display("{}", source))] Server { source: apiserver::server::Error }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } /// Stores user-supplied arguments. struct Args { datastore_path: String, + log_level: LevelFilter, socket_gid: Option, socket_path: String, - verbosity: usize, } /// Informs the user about proper usage of the program and exits. @@ -58,7 +54,7 @@ fn usage() -> ! { [ --socket-path PATH ] [ --socket-gid GROUP_ID ] [ --no-color ] - [ --verbose --verbose ... ] + [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", program_name, DEFAULT_BIND_PATH @@ -75,15 +71,13 @@ fn usage_msg>(msg: S) -> ! { /// Parses user arguments into an Args structure. fn parse_args(args: env::Args) -> Args { let mut datastore_path = None; + let mut log_level = None; let mut socket_gid = None; let mut socket_path = None; - let mut verbosity = 1; let mut iter = args.skip(1); while let Some(arg) = iter.next() { match arg.as_ref() { - "-v" | "--verbose" => verbosity += 1, - "--datastore-path" => { datastore_path = Some( iter.next() @@ -91,6 +85,15 @@ fn parse_args(args: env::Args) -> Args { ) } + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } + "--socket-path" => { socket_path = Some( iter.next() @@ -117,8 +120,8 @@ fn parse_args(args: env::Args) -> Args { Args { socket_gid, - verbosity, datastore_path: datastore_path.unwrap_or_else(|| usage()), + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), socket_path: socket_path.unwrap_or_else(|| DEFAULT_BIND_PATH.to_string()), } } @@ -127,18 +130,9 @@ fn parse_args(args: env::Args) -> Args { fn main() -> Result<()> { let args = parse_args(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; // Make sure the datastore exists ensure!( diff --git a/workspaces/api/apiserver/src/lib.rs b/workspaces/api/apiserver/src/lib.rs index 41233e8bf1a..a64ba371f2d 100644 --- a/workspaces/api/apiserver/src/lib.rs +++ b/workspaces/api/apiserver/src/lib.rs @@ -75,7 +75,7 @@ See `../../apiclient/README.md` for client examples. #![deny(rust_2018_idioms)] #[macro_use] -extern crate tracing; +extern crate log; pub mod datastore; pub mod model; diff --git a/workspaces/api/data_store_version/Cargo.toml b/workspaces/api/data_store_version/Cargo.toml index 1f14a5d8723..fb3015e24e5 100644 --- a/workspaces/api/data_store_version/Cargo.toml +++ b/workspaces/api/data_store_version/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] lazy_static = "1.2" -tracing = "0.1" +log = "0.4" regex = "1.1" snafu = "0.5" diff --git a/workspaces/api/data_store_version/src/lib.rs b/workspaces/api/data_store_version/src/lib.rs index c7f9ad5edd0..01bb5341599 100644 --- a/workspaces/api/data_store_version/src/lib.rs +++ b/workspaces/api/data_store_version/src/lib.rs @@ -10,7 +10,7 @@ It is especially helpful during data store migrations, and is also used for data #![deny(rust_2018_idioms)] #[macro_use] -extern crate tracing; +extern crate log; use lazy_static::lazy_static; use regex::Regex; diff --git a/workspaces/api/host-containers/Cargo.toml b/workspaces/api/host-containers/Cargo.toml index ca77b3f968a..6dae489c81d 100644 --- a/workspaces/api/host-containers/Cargo.toml +++ b/workspaces/api/host-containers/Cargo.toml @@ -10,11 +10,11 @@ build = "build.rs" apiclient = { path = "../apiclient" } apiserver = { path = "../apiserver" } http = "0.1" -tracing = "0.1" +log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1" +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" [build-dependencies] cargo-readme = "3.1" diff --git a/workspaces/api/host-containers/src/main.rs b/workspaces/api/host-containers/src/main.rs index ee1b3b0fc8e..be9b24bf0ec 100644 --- a/workspaces/api/host-containers/src/main.rs +++ b/workspaces/api/host-containers/src/main.rs @@ -8,6 +8,10 @@ on its 'enabled' flag. #![deny(rust_2018_idioms)] +#[macro_use] +extern crate log; + +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{ensure, OptionExt, ResultExt}; use std::collections::HashMap; use std::env; @@ -16,18 +20,11 @@ use std::fmt::Write; use std::fs; use std::path::{Path, PathBuf}; use std::process::{self, Command}; +use std::str::FromStr; use apiserver::model; use apiserver::modeled_types::Identifier; -#[macro_use] -extern crate tracing; - -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; - // FIXME Get from configuration in the future const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const API_SETTINGS_URI: &str = "/settings"; @@ -98,13 +95,11 @@ mod error { std::str::from_utf8(&output.stderr).unwrap_or_else(|_| "")))] SystemdCommandFailure { output: Output }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, - #[snafu(display("Failed to manage {} of {} host containers", failed, tried))] ManageContainersFailed { failed: usize, tried: usize }, + + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } @@ -212,8 +207,8 @@ where /// Store the args we receive on the command line struct Args { + log_level: LevelFilter, socket_path: PathBuf, - verbosity: usize, } /// Print a usage message in the event a bad arg is passed @@ -222,7 +217,7 @@ fn usage() -> ! { eprintln!( r"Usage: {} [ --socket-path PATH ] - [ --verbose --verbose ... ] + [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", program_name, DEFAULT_API_SOCKET, @@ -238,13 +233,20 @@ fn usage_msg>(msg: S) -> ! { /// Parse the args to the program and return an Args struct fn parse_args(args: env::Args) -> Args { + let mut log_level = None; let mut socket_path = None; - let mut verbosity = 3; let mut iter = args.skip(1); while let Some(arg) = iter.next() { match arg.as_ref() { - "-v" | "--verbose" => verbosity += 1, + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } "--socket-path" => { socket_path = Some( @@ -259,8 +261,8 @@ fn parse_args(args: env::Args) -> Args { } Args { + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.into()), - verbosity, } } @@ -307,18 +309,9 @@ where fn main() -> Result<()> { let args = parse_args(env::args()); - // Start the logger - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; info!("host-containers started"); diff --git a/workspaces/api/migration/migrator/Cargo.toml b/workspaces/api/migration/migrator/Cargo.toml index 7dbd30a490e..245637ec33b 100644 --- a/workspaces/api/migration/migrator/Cargo.toml +++ b/workspaces/api/migration/migrator/Cargo.toml @@ -10,12 +10,12 @@ build = "build.rs" data_store_version = { path = "../../data_store_version" } fs_extra = "1.1" lazy_static = "1.2" -tracing = "0.1" +log = "0.4" nix = "0.15" rand = { version = "0.7", default-features = false, features = ["std"] } regex = "1.1" +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" [build-dependencies] cargo-readme = "3.1" diff --git a/workspaces/api/migration/migrator/src/args.rs b/workspaces/api/migration/migrator/src/args.rs index 848aad71654..06788803fe9 100644 --- a/workspaces/api/migration/migrator/src/args.rs +++ b/workspaces/api/migration/migrator/src/args.rs @@ -1,6 +1,7 @@ //! This module handles argument parsing for the migrator binary. use data_store_version::Version; +use simplelog::LevelFilter; use std::env; use std::fs; use std::path::{Path, PathBuf}; @@ -16,7 +17,7 @@ fn usage() -> ! { --migration-directories PATH[:PATH:PATH...] (--migrate-to-version x.y | --migrate-to-version-from-file PATH) [ --no-color ] - [ --verbose --verbose ... ]", + [ --log-level trace|debug|info|warn|error ]", program_name ); process::exit(2); @@ -31,9 +32,9 @@ fn usage_msg>(msg: S) -> ! { /// Stores user-supplied arguments. pub(crate) struct Args { pub(crate) datastore_path: PathBuf, + pub(crate) log_level: LevelFilter, pub(crate) migration_directories: Vec, pub(crate) migrate_to_version: Version, - pub(crate) verbosity: usize, } impl Args { @@ -41,10 +42,9 @@ impl Args { pub(crate) fn from_env(args: env::Args) -> Self { // Required parameters. let mut datastore_path = None; + let mut log_level = None; let mut migration_directories = None; let mut migrate_to_version = None; - // Optional parameters with their defaults. - let mut verbosity = 3; // default to INFO level let mut iter = args.skip(1); while let Some(arg) = iter.next() { @@ -74,6 +74,15 @@ impl Args { datastore_path = Some(canonical); } + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } + "--migration-directories" => { let paths_str = iter.next().unwrap_or_else(|| { usage_msg("Did not give argument to --migration-directories") @@ -114,17 +123,15 @@ impl Args { migrate_to_version = Some(version) } - "-v" | "--verbose" => verbosity += 1, - _ => usage(), } } Self { datastore_path: datastore_path.unwrap_or_else(|| usage()), + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), migration_directories: migration_directories.unwrap_or_else(|| usage()), migrate_to_version: migrate_to_version.unwrap_or_else(|| usage()), - verbosity, } } } diff --git a/workspaces/api/migration/migrator/src/error.rs b/workspaces/api/migration/migrator/src/error.rs index b0ade4078f7..c8d8c688753 100644 --- a/workspaces/api/migration/migrator/src/error.rs +++ b/workspaces/api/migration/migrator/src/error.rs @@ -11,11 +11,6 @@ use std::process::{Command, Output}; #[derive(Debug, Snafu)] #[snafu(visibility = "pub(crate)")] pub(crate) enum Error { - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, - #[snafu(display("Internal error: {}", msg))] Internal { msg: String }, @@ -81,6 +76,9 @@ pub(crate) enum Error { #[snafu(display("Migration path '{}' contains invalid UTF-8", path.display()))] MigrationNameNotUTF8 { path: PathBuf }, + + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } /// Result alias containing our Error type. diff --git a/workspaces/api/migration/migrator/src/main.rs b/workspaces/api/migration/migrator/src/main.rs index 84594f4fb1c..2323093cdee 100644 --- a/workspaces/api/migration/migrator/src/main.rs +++ b/workspaces/api/migration/migrator/src/main.rs @@ -19,13 +19,14 @@ #![deny(rust_2018_idioms)] #[macro_use] -extern crate tracing; +extern crate log; use data_store_version::{Version, VERSION_RE}; use lazy_static::lazy_static; use nix::{dir::Dir, fcntl::OFlag, sys::stat::Mode, unistd::fsync}; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use regex::Regex; +use simplelog::{Config as LogConfig, TermLogger, TerminalMode}; use snafu::{ensure, OptionExt, ResultExt}; use std::env; use std::fs; @@ -34,10 +35,6 @@ use std::os::unix::io::AsRawFd; use std::path::{Path, PathBuf}; use std::process::{self, Command}; use std::str::FromStr; -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; mod args; mod direction; @@ -69,18 +66,10 @@ fn main() { fn run() -> Result<()> { let args = Args::from_env(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; + // We don't handle data store format (major version) migrations because they could change // anything about our storage; they're handled by more free-form binaries run by a separate // startup service. diff --git a/workspaces/api/moondog/Cargo.toml b/workspaces/api/moondog/Cargo.toml index 68c06774550..b2176995d39 100644 --- a/workspaces/api/moondog/Cargo.toml +++ b/workspaces/api/moondog/Cargo.toml @@ -10,12 +10,12 @@ build = "build.rs" apiclient = { path = "../apiclient" } apiserver = { path = "../apiserver" } http = "0.1" -tracing = "0.1" +log = "0.4" reqwest = { version = "0.9", default-features = false, features = [] } serde = { version = "1.0", features = ["derive"] } serde_json = "1" +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" toml = "0.5" [build-dependencies] diff --git a/workspaces/api/moondog/src/main.rs b/workspaces/api/moondog/src/main.rs index 250c09e2cc9..c38bd5c5922 100644 --- a/workspaces/api/moondog/src/main.rs +++ b/workspaces/api/moondog/src/main.rs @@ -13,17 +13,15 @@ User data can also be retrieved from a file for testing. #![deny(rust_2018_idioms)] #[macro_use] -extern crate tracing; +extern crate log; use http::StatusCode; use serde::Serialize; +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{ensure, OptionExt, ResultExt}; use std::path::Path; +use std::str::FromStr; use std::{env, fs, process}; -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; // TODO // Tests! @@ -86,11 +84,6 @@ mod error { #[snafu(display("Error serializing TOML to JSON: {}", source))] SettingsToJSON { source: serde_json::error::Error }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, - #[snafu(display("Unable to read user data input file '{}': {}", path.display(), source))] InputFileRead { path: PathBuf, source: io::Error }, @@ -102,6 +95,9 @@ mod error { #[snafu(display("Error {} requesting data from IMDS: {}", code, response))] IMDSRequest { code: StatusCode, response: String }, + + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } use error::MoondogError; @@ -225,7 +221,7 @@ impl RawUserData { /// Store the args we receive on the command line struct Args { - verbosity: usize, + log_level: LevelFilter, socket_path: String, } @@ -235,7 +231,7 @@ fn usage() -> ! { eprintln!( r"Usage: {} [ --socket-path PATH ] - [ --verbose --verbose ... ] + [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", program_name, DEFAULT_API_SOCKET, @@ -251,8 +247,8 @@ fn usage_msg>(msg: S) -> ! { /// Parse the args to the program and return an Args struct fn parse_args(args: env::Args) -> Args { + let mut log_level = None; let mut socket_path = None; - let mut verbosity = 3; let mut iter = args.skip(1); while let Some(arg) = iter.next() { @@ -264,14 +260,22 @@ fn parse_args(args: env::Args) -> Args { ) } - "-v" | "--verbose" => verbosity += 1, + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } + _ => usage(), } } Args { + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), - verbosity, } } @@ -279,18 +283,9 @@ fn main() -> Result<()> { // Parse and store the args passed to the program let args = parse_args(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; info!("Moondog started"); diff --git a/workspaces/api/pluto/Cargo.toml b/workspaces/api/pluto/Cargo.toml index 9b9ba61b846..ddc290c5692 100644 --- a/workspaces/api/pluto/Cargo.toml +++ b/workspaces/api/pluto/Cargo.toml @@ -10,8 +10,6 @@ build = "build.rs" reqwest = { version = "0.9", default-features = false, features = []} serde_json = "1" snafu = "0.5" -tracing = "0.1" -tracing-subscriber = "0.1" [build-dependencies] cargo-readme = "3.1" diff --git a/workspaces/api/servicedog/Cargo.toml b/workspaces/api/servicedog/Cargo.toml index 1239360b386..d62bc4d9564 100644 --- a/workspaces/api/servicedog/Cargo.toml +++ b/workspaces/api/servicedog/Cargo.toml @@ -10,11 +10,11 @@ build = "build.rs" apiclient = { path = "../apiclient" } apiserver = { path = "../apiserver" } http = "0.1" -tracing = "0.1" +log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1" +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" [build-dependencies] cargo-readme = "3.1" diff --git a/workspaces/api/servicedog/src/main.rs b/workspaces/api/servicedog/src/main.rs index 54c026b48a0..a99f69367b3 100644 --- a/workspaces/api/servicedog/src/main.rs +++ b/workspaces/api/servicedog/src/main.rs @@ -15,22 +15,19 @@ As its very last step, service dog calls `systemd daemon-reload` to ensure all c #![deny(rust_2018_idioms)] +#[macro_use] +extern crate log; + +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{ensure, OptionExt, ResultExt}; use std::env; use std::ffi::OsStr; use std::process::{self, Command}; +use std::str::FromStr; use apiserver::datastore::serialization::to_pairs_with_prefix; use apiserver::model; -#[macro_use] -extern crate tracing; - -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; - // FIXME Get from configuration in the future const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const API_SETTINGS_URI: &str = "/settings"; @@ -97,10 +94,8 @@ mod error { std::str::from_utf8(&output.stderr).unwrap_or_else(|_| "")))] SystemdCommandFailure { output: Output }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } @@ -250,9 +245,9 @@ where /// Store the args we receive on the command line struct Args { + log_level: LevelFilter, setting: String, systemd_unit: String, - verbosity: usize, } /// Print a usage message in the event a bad arg is passed @@ -262,7 +257,7 @@ fn usage() -> ! { r"Usage: {} [ -s | --setting SETTING ] [ -u | --systemd-unit UNIT ] - [ --verbose --verbose ... ]", + [ --log-level trace|debug|info|warn|error ]", program_name ); process::exit(2); @@ -276,14 +271,21 @@ fn usage_msg>(msg: S) -> ! { /// Parse the args to the program and return an Args struct fn parse_args(args: env::Args) -> Args { + let mut log_level = None; let mut setting = None; let mut systemd_unit = None; - let mut verbosity = 3; let mut iter = args.skip(1); while let Some(arg) = iter.next() { match arg.as_ref() { - "-v" | "--verbose" => verbosity += 1, + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } "-s" | "--setting" => { setting = Some( @@ -291,6 +293,7 @@ fn parse_args(args: env::Args) -> Args { .unwrap_or_else(|| usage_msg("Did not give argument to -s | --setting")), ) } + "-u" | "--systemd-unit" => { systemd_unit = Some(iter.next().unwrap_or_else(|| { @@ -303,10 +306,10 @@ fn parse_args(args: env::Args) -> Args { } Args { + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), setting: setting.unwrap_or_else(|| usage_msg("-s|--setting is a required argument")), systemd_unit: systemd_unit .unwrap_or_else(|| usage_msg("-u|--systemd-unit is a required argument")), - verbosity, } } @@ -314,18 +317,10 @@ fn main() -> Result<()> { // Parse and store the args passed to the program let args = parse_args(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; + info!("servicedog started for unit {}", &args.systemd_unit); let systemd_unit = SystemdUnit::new(&args.systemd_unit); diff --git a/workspaces/api/settings-committer/Cargo.toml b/workspaces/api/settings-committer/Cargo.toml index 7ca85b01890..d81b5fa2594 100644 --- a/workspaces/api/settings-committer/Cargo.toml +++ b/workspaces/api/settings-committer/Cargo.toml @@ -10,10 +10,10 @@ build = "build.rs" apiclient = { path = "../apiclient" } snafu = "0.5" http = "0.1" +log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1" -tracing = "0.1" -tracing-subscriber = "0.1" +simplelog = "0.7" [build-dependencies] cargo-readme = "3.1" diff --git a/workspaces/api/settings-committer/src/main.rs b/workspaces/api/settings-committer/src/main.rs index 4feed412006..3ffdf252722 100644 --- a/workspaces/api/settings-committer/src/main.rs +++ b/workspaces/api/settings-committer/src/main.rs @@ -8,16 +8,12 @@ settings. It logs any pending settings, then commits them to live. #![deny(rust_2018_idioms)] #[macro_use] -extern crate tracing; - -use std::{collections::HashMap, env, process}; - -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; +extern crate log; +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{ensure, ResultExt}; +use std::str::FromStr; +use std::{collections::HashMap, env, process}; const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const API_PENDING_URI: &str = "/settings/pending"; @@ -48,10 +44,8 @@ mod error { response_body: String, }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } @@ -118,8 +112,8 @@ fn commit_pending_settings>(socket_path: S) -> Result<()> { /// Store the args we receive on the command line struct Args { + log_level: LevelFilter, socket_path: String, - verbosity: usize, } /// Print a usage message in the event a bad arg is passed @@ -128,7 +122,8 @@ fn usage() -> ! { eprintln!( r"Usage: {} [ --socket-path PATH ] - [ --verbose --verbose ... ] + [ --log-level trace|debug|info|warn|error ] + Socket path defaults to {}", program_name, DEFAULT_API_SOCKET ); @@ -143,13 +138,21 @@ fn usage_msg>(msg: S) -> ! { /// Parse the args to the program and return an Args struct fn parse_args(args: env::Args) -> Args { + let mut log_level = None; let mut socket_path = None; - let mut verbosity = 3; let mut iter = args.skip(1); while let Some(arg) = iter.next() { match arg.as_ref() { - "-v" | "--verbose" => verbosity += 1, + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } + "--socket-path" => { socket_path = Some( iter.next() @@ -161,26 +164,18 @@ fn parse_args(args: env::Args) -> Args { } Args { + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), - verbosity, } } fn main() -> Result<()> { // Parse and store the args passed to the program let args = parse_args(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; info!("Checking pending settings."); check_pending_settings(&args.socket_path); diff --git a/workspaces/api/storewolf/Cargo.toml b/workspaces/api/storewolf/Cargo.toml index 4960f191108..e4e5adf4929 100644 --- a/workspaces/api/storewolf/Cargo.toml +++ b/workspaces/api/storewolf/Cargo.toml @@ -9,10 +9,10 @@ build = "build.rs" [dependencies] apiserver = { path = "../apiserver" } data_store_version = { path = "../data_store_version" } -tracing = "0.1" +log = "0.4" rand = { version = "0.7", default-features = false, features = ["std"] } +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" toml = "0.5" [build-dependencies] diff --git a/workspaces/api/storewolf/src/main.rs b/workspaces/api/storewolf/src/main.rs index ca714a0f9c1..49ba78c1a31 100644 --- a/workspaces/api/storewolf/src/main.rs +++ b/workspaces/api/storewolf/src/main.rs @@ -8,7 +8,11 @@ settings given in the defaults.toml file, unless they already exist. */ #![deny(rust_2018_idioms)] +#[macro_use] +extern crate log; + use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{OptionExt, ResultExt}; use std::collections::{HashMap, HashSet}; use std::io; @@ -16,10 +20,6 @@ use std::os::unix::fs::symlink; use std::path::Path; use std::str::FromStr; use std::{env, fs, process}; -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; use apiserver::datastore::key::{Key, KeyType}; use apiserver::datastore::serialization::{to_pairs, to_pairs_with_prefix}; @@ -27,9 +27,6 @@ use apiserver::datastore::{self, DataStore, FilesystemDataStore, ScalarError}; use apiserver::model; use data_store_version::Version; -#[macro_use] -extern crate tracing; - // FIXME Get these from configuration in the future const DATASTORE_VERSION_FILE: &str = "/usr/share/thar/data-store-version"; @@ -104,10 +101,8 @@ mod error { #[snafu(display("Data store link '{}' points to /", path.display()))] DataStoreLinkToRoot { path: PathBuf }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } @@ -356,7 +351,7 @@ fn populate_default_datastore>( /// Store the args we receive on the command line struct Args { data_store_base_path: String, - verbosity: usize, + log_level: LevelFilter, version: Option, } @@ -367,7 +362,7 @@ fn usage() -> ! { r"Usage: {} --data-store-base-path PATH [ --version X.Y ] - [ --verbose --verbose ... ] + [ --log-level trace|debug|info|warn|error ] If --version is not given, the version will be pulled from /usr/share/thar/data-store-version. This is used to set up versioned symlinks in the data store base path. @@ -386,20 +381,27 @@ fn usage_msg>(msg: S) -> ! { /// Parse the args to the program and return an Args struct fn parse_args(args: env::Args) -> Args { let mut data_store_base_path = None; - let mut verbosity = 3; + let mut log_level = None; let mut version = None; let mut iter = args.skip(1); while let Some(arg) = iter.next() { match arg.as_ref() { - "-v" | "--verbose" => verbosity += 1, - "--data-store-base-path" => { data_store_base_path = Some(iter.next().unwrap_or_else(|| { usage_msg("Did not give argument to --data-store-base-path") })) } + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } + "--version" => { let version_str = iter .next() @@ -416,7 +418,7 @@ fn parse_args(args: env::Args) -> Args { Args { data_store_base_path: data_store_base_path.unwrap_or_else(|| usage()), - verbosity, + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), version, } } @@ -425,18 +427,9 @@ fn main() -> Result<()> { // Parse and store the args passed to the program let args = parse_args(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; info!("Storewolf started"); diff --git a/workspaces/api/sundog/Cargo.toml b/workspaces/api/sundog/Cargo.toml index 0d54bdc0b6b..bc751097483 100644 --- a/workspaces/api/sundog/Cargo.toml +++ b/workspaces/api/sundog/Cargo.toml @@ -10,11 +10,11 @@ build = "build.rs" apiclient = { path = "../apiclient" } apiserver = { path = "../apiserver" } http = "0.1" -tracing = "0.1" +log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1" +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" [build-dependencies] cargo-readme = "3.1" diff --git a/workspaces/api/sundog/src/main.rs b/workspaces/api/sundog/src/main.rs index a27be95b498..b8144fbc7e1 100644 --- a/workspaces/api/sundog/src/main.rs +++ b/workspaces/api/sundog/src/main.rs @@ -9,23 +9,20 @@ The output is collected and sent to a known Thar API server endpoint. #![deny(rust_2018_idioms)] +#[macro_use] +extern crate log; + +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{ensure, OptionExt, ResultExt}; use std::collections::{HashMap, HashSet}; use std::env; use std::path::Path; use std::process; -use std::str; +use std::str::{self, FromStr}; use apiserver::datastore::serialization::to_pairs_with_prefix; use apiserver::datastore::{self, deserialization}; use apiserver::model; -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; - -#[macro_use] -extern crate tracing; // FIXME Get from configuration in the future const DEFAULT_API_SOCKET: &str = "/run/api.sock"; @@ -139,16 +136,14 @@ mod error { #[snafu(display("Error serializing Settings: {} ", source))] SerializeSettings { source: serialization::Error }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, - #[snafu(display("Error serializing command output '{}': {}", value, source))] SerializeScalar { value: serde_json::Value, source: datastore::ScalarError, }, + + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } @@ -381,7 +376,7 @@ where /// Store the args we receive on the command line struct Args { - verbosity: usize, + log_level: LevelFilter, socket_path: String, } @@ -391,7 +386,7 @@ fn usage() -> ! { eprintln!( r"Usage: {} [ --socket-path PATH ] - [ --verbose --verbose ... ] + [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", program_name, DEFAULT_API_SOCKET, @@ -407,13 +402,20 @@ fn usage_msg>(msg: S) -> ! { /// Parse the args to the program and return an Args struct fn parse_args(args: env::Args) -> Args { + let mut log_level = None; let mut socket_path = None; - let mut verbosity = 3; let mut iter = args.skip(1); while let Some(arg) = iter.next() { match arg.as_ref() { - "-v" | "--verbose" => verbosity += 1, + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } "--socket-path" => { socket_path = Some( @@ -427,8 +429,8 @@ fn parse_args(args: env::Args) -> Args { } Args { + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), - verbosity, } } @@ -436,18 +438,9 @@ fn main() -> Result<()> { // Parse and store the args passed to the program let args = parse_args(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; info!("Sundog started"); diff --git a/workspaces/api/thar-be-settings/Cargo.toml b/workspaces/api/thar-be-settings/Cargo.toml index 535c63c7c56..9e464ec2d51 100644 --- a/workspaces/api/thar-be-settings/Cargo.toml +++ b/workspaces/api/thar-be-settings/Cargo.toml @@ -13,11 +13,11 @@ base64 = "0.10" handlebars = "2.0" http = "0.1" itertools = "0.8" -tracing = "0.1" +log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1" +simplelog = "0.7" snafu = "0.5" -tracing-subscriber = "0.1" [build-dependencies] cargo-readme = "3.1" diff --git a/workspaces/api/thar-be-settings/src/error.rs b/workspaces/api/thar-be-settings/src/error.rs index a32b19c8117..8ed9c88fbe3 100644 --- a/workspaces/api/thar-be-settings/src/error.rs +++ b/workspaces/api/thar-be-settings/src/error.rs @@ -75,9 +75,4 @@ pub enum TBSError { uri: String, source: serde_json::Error, }, - - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, } diff --git a/workspaces/api/thar-be-settings/src/lib.rs b/workspaces/api/thar-be-settings/src/lib.rs index f6509dd0fc2..2926c7f6d76 100644 --- a/workspaces/api/thar-be-settings/src/lib.rs +++ b/workspaces/api/thar-be-settings/src/lib.rs @@ -17,7 +17,7 @@ In the standalone ("all keys") mode, it queries the API for all services and con #![deny(rust_2018_idioms)] #[macro_use] -extern crate tracing; +extern crate log; use snafu::ResultExt; use std::collections::HashSet; diff --git a/workspaces/api/thar-be-settings/src/main.rs b/workspaces/api/thar-be-settings/src/main.rs index 963ea3e7e68..7f3a74f00fb 100644 --- a/workspaces/api/thar-be-settings/src/main.rs +++ b/workspaces/api/thar-be-settings/src/main.rs @@ -1,14 +1,12 @@ #[macro_use] -extern crate tracing; +extern crate log; +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::ResultExt; use std::collections::HashSet; use std::env; use std::process; -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; +use std::str::FromStr; use thar_be_settings::{config, get_changed_settings, service, settings, template}; @@ -21,10 +19,8 @@ mod error { #[derive(Debug, Snafu)] #[snafu(visibility = "pub(super)")] pub(super) enum Error { - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, } } @@ -39,8 +35,8 @@ enum RunMode { /// Store the args we receive on the command line struct Args { + log_level: LevelFilter, mode: RunMode, - verbosity: usize, socket_path: String, } @@ -51,7 +47,7 @@ fn usage() -> ! { r"Usage: {} [ --all ] [ --socket-path PATH ] - [ --verbose --verbose ... ] + [ --log-level trace|debug|info|warn|error ] If --all is given, all configuration files will be written and all services will have their restart-commands run. Otherwise, settings keys @@ -72,8 +68,8 @@ fn usage_msg>(msg: S) -> ! { /// Parse the args to the program and return an Args struct fn parse_args(args: env::Args) -> Args { + let mut log_level = None; let mut mode = RunMode::SpecificKeys; - let mut verbosity = 3; let mut socket_path = None; let mut iter = args.skip(1); @@ -81,7 +77,14 @@ fn parse_args(args: env::Args) -> Args { match arg.as_ref() { "--all" => mode = RunMode::All, - "-v" | "--verbose" => verbosity += 1, + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); + } "--socket-path" => { socket_path = Some( @@ -96,7 +99,7 @@ fn parse_args(args: env::Args) -> Args { Args { mode, - verbosity, + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), } } @@ -139,18 +142,9 @@ fn main() -> Result<(), Box> { // Parse and store the args passed to the program let args = parse_args(env::args()); - let level: LevelFilter = args - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init(args.log_level, LogConfig::default(), TerminalMode::Mixed) + .context(error::Logger)?; info!("thar-be-settings started"); diff --git a/workspaces/updater/updog/Cargo.toml b/workspaces/updater/updog/Cargo.toml index 10087c98779..9340071d757 100644 --- a/workspaces/updater/updog/Cargo.toml +++ b/workspaces/updater/updog/Cargo.toml @@ -8,6 +8,7 @@ publish = false [dependencies] chrono = "0.4.9" data_store_version = { path = "../../api/data_store_version" } +log = "0.4" lz4 = "1.23.1" rand = "0.7.0" regex = "1.1" @@ -16,9 +17,8 @@ serde = "1.0.100" serde_json = "1.0.40" serde_plain = "0.3.0" signpost = { path = "../signpost" } +simplelog = "0.7" snafu = "0.5.0" -tracing = "0.1" -tracing-subscriber = "0.1" time = "0.1" toml = "0.5.1" tough = { path = "../tough" } diff --git a/workspaces/updater/updog/src/error.rs b/workspaces/updater/updog/src/error.rs index c996bb8a3d2..6068e85fc76 100644 --- a/workspaces/updater/updog/src/error.rs +++ b/workspaces/updater/updog/src/error.rs @@ -80,6 +80,9 @@ pub(crate) enum Error { #[snafu(display("Duplicate version key: {}", key))] DuplicateVersionKey { backtrace: Backtrace, key: String }, + #[snafu(display("Logger setup error: {}", source))] + Logger { source: simplelog::TermLogError }, + #[snafu(display("Failed to attach image to loop device"))] LoopAttachFailed { backtrace: Backtrace, @@ -210,11 +213,6 @@ pub(crate) enum Error { source: std::io::Error, }, - #[snafu(display("Failed to parse provided directive: {}", source))] - TracingDirectiveParse { - source: tracing_subscriber::filter::LevelParseError, - }, - #[snafu(display("Failed to serialize update information: {}", source))] UpdateSerialize { source: serde_json::Error, diff --git a/workspaces/updater/updog/src/main.rs b/workspaces/updater/updog/src/main.rs index b1c0a2b5339..178f2c12165 100644 --- a/workspaces/updater/updog/src/main.rs +++ b/workspaces/updater/updog/src/main.rs @@ -12,6 +12,7 @@ use rand::{thread_rng, Rng}; use semver::Version; use serde::{Deserialize, Serialize}; use signpost::State; +use simplelog::{Config as LogConfig, LevelFilter, TermLogger, TerminalMode}; use snafu::{ErrorCompat, OptionExt, ResultExt}; use std::collections::BTreeMap; use std::fs::{self, File, OpenOptions}; @@ -19,11 +20,8 @@ use std::io::{self, BufRead, BufReader}; use std::ops::Bound::{Excluded, Included}; use std::path::Path; use std::process; +use std::str::FromStr; use tough::{Limits, Repository, Settings}; -use tracing_subscriber::{ - filter::{EnvFilter, LevelFilter}, - FmtSubscriber, -}; #[cfg(target_arch = "x86_64")] const TARGET_ARCH: &str = "x86_64"; @@ -126,6 +124,12 @@ struct Manifest { datastore_versions: BTreeMap, } +/// Prints a more specific message before exiting through usage(). +fn usage_msg>(msg: S) -> ! { + eprintln!("{}\n", msg.as_ref()); + usage(); +} + fn usage() -> ! { #[rustfmt::skip] eprintln!("\ @@ -154,7 +158,7 @@ SUBCOMMANDS: GLOBAL OPTIONS: [ -j | --json ] JSON-formatted output - [ --verbose --verbose ... ] Increase log verbosity"); + [ --log-level trace|debug|info|warn|error ] Set logging verbosity"); std::process::exit(1) } @@ -391,7 +395,7 @@ fn update_flags() -> Result<()> { /// Struct to hold the specified command line argument values struct Arguments { subcommand: String, - verbosity: usize, + log_level: LevelFilter, json: bool, ignore_wave: bool, force_version: Option, @@ -403,7 +407,7 @@ struct Arguments { /// Parse the command line arguments to get the user-specified values fn parse_args(args: std::env::Args) -> Arguments { let mut subcommand = None; - let mut verbosity: usize = 3; // Default log level to 3 (Info) + let mut log_level = None; let mut update_version = None; let mut ignore_wave = false; let mut json = false; @@ -414,8 +418,13 @@ fn parse_args(args: std::env::Args) -> Arguments { let mut iter = args.skip(1); while let Some(arg) = iter.next() { match arg.as_ref() { - "-v" | "--verbose" => { - verbosity += 1; + "--log-level" => { + let log_level_str = iter + .next() + .unwrap_or_else(|| usage_msg("Did not give argument to --log-level")); + log_level = Some(LevelFilter::from_str(&log_level_str).unwrap_or_else(|_| { + usage_msg(format!("Invalid log level '{}'", log_level_str)) + })); } "-i" | "--image" => match iter.next() { Some(v) => match Version::parse(&v) { @@ -456,7 +465,7 @@ fn parse_args(args: std::env::Args) -> Arguments { Arguments { subcommand: subcommand.unwrap_or_else(|| usage()), - verbosity, + log_level: log_level.unwrap_or_else(|| LevelFilter::Info), json, ignore_wave, force_version: update_version, @@ -482,18 +491,13 @@ fn main_inner() -> Result<()> { // Parse and store the arguments passed to the program let arguments = parse_args(std::env::args()); - let level: LevelFilter = arguments - .verbosity - .to_string() - .parse() - .context(error::TracingDirectiveParse)?; - let filter = EnvFilter::from_default_env().add_directive(level.into()); - let subscriber = FmtSubscriber::builder() - .with_env_filter(filter) - .with_writer(std::io::stderr) - .finish(); - // Start the logger - tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); + // TerminalMode::Mixed will send errors to stderr and anything less to stdout. + TermLogger::init( + arguments.log_level, + LogConfig::default(), + TerminalMode::Mixed, + ) + .context(error::Logger)?; let command = serde_plain::from_str::(&arguments.subcommand).unwrap_or_else(|_| usage()); diff --git a/workspaces/webpki-roots-shim/Cargo.toml b/workspaces/webpki-roots-shim/Cargo.toml index 2c3cd4cb42b..a07b6d663bf 100644 --- a/workspaces/webpki-roots-shim/Cargo.toml +++ b/workspaces/webpki-roots-shim/Cargo.toml @@ -7,6 +7,6 @@ publish = false [dependencies] lazy_static = "1.4.0" -tracing = "0.1" +log = "0.4" pem = "0.6.1" webpki = "0.21.0" diff --git a/workspaces/webpki-roots-shim/src/lib.rs b/workspaces/webpki-roots-shim/src/lib.rs index f10b7768e93..39bb1693b92 100644 --- a/workspaces/webpki-roots-shim/src/lib.rs +++ b/workspaces/webpki-roots-shim/src/lib.rs @@ -1,6 +1,9 @@ #![deny(rust_2018_idioms)] #![warn(clippy::pedantic)] +#[macro_use] +extern crate log; + use pem::Pem; use std::borrow::Cow; use std::path::{Path, PathBuf}; @@ -9,8 +12,8 @@ use webpki::{TLSServerTrustAnchors, TrustAnchor}; lazy_static::lazy_static! { pub static ref TLS_SERVER_ROOTS: TLSServerTrustAnchors<'static> = { - tracing::debug!("webpki-roots-shim activated, {} certificates", ROOTS.len()); - tracing::debug!("certificate source: {}", CERT_PATH.display()); + debug!("webpki-roots-shim activated, {} certificates", ROOTS.len()); + debug!("certificate source: {}", CERT_PATH.display()); TLSServerTrustAnchors(&ROOTS) }; @@ -31,7 +34,7 @@ fn tls_server_roots_pem() -> Vec { v } Err(err) => { - tracing::error!("failed to read {}: {}", CERT_PATH.display(), err); + error!("failed to read {}: {}", CERT_PATH.display(), err); Vec::new() } } From c32594ed3ff927056ce396e0b62fa6e741e692e8 Mon Sep 17 00:00:00 2001 From: Tom Kirchner Date: Mon, 28 Oct 2019 11:00:31 -0700 Subject: [PATCH 2/2] Expose first-party stderr (now only errors) to console --- packages/release/prepare-local.service | 1 + packages/workspaces/apiserver.service | 1 + packages/workspaces/migrator.service | 1 + packages/workspaces/moondog.service | 1 + packages/workspaces/settings-applier.service | 1 + packages/workspaces/settings-committer.service | 1 + packages/workspaces/storewolf.service | 1 + packages/workspaces/sundog.service | 1 + packages/workspaces/updog.service | 1 + 9 files changed, 9 insertions(+) diff --git a/packages/release/prepare-local.service b/packages/release/prepare-local.service index 4990e0d088e..47ed2c71bfd 100644 --- a/packages/release/prepare-local.service +++ b/packages/release/prepare-local.service @@ -36,6 +36,7 @@ ExecStart=/usr/lib/systemd/systemd-growfs ${LOCAL_DIR} ExecStart=/usr/bin/mkdir -p ${LOCAL_DIR}/var ${LOCAL_DIR}/opt RemainAfterExit=false +StandardError=journal+console [Install] WantedBy=local-fs.target diff --git a/packages/workspaces/apiserver.service b/packages/workspaces/apiserver.service index f5c9802e658..ac2e3bea88f 100644 --- a/packages/workspaces/apiserver.service +++ b/packages/workspaces/apiserver.service @@ -6,6 +6,7 @@ Requires=storewolf.service migrator.service [Service] Type=notify ExecStart=/usr/bin/apiserver --datastore-path /var/lib/thar/datastore/current --socket-gid 274 +StandardError=journal+console [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/migrator.service b/packages/workspaces/migrator.service index 9d1ed9fd817..f71c77c344e 100644 --- a/packages/workspaces/migrator.service +++ b/packages/workspaces/migrator.service @@ -5,6 +5,7 @@ Description=Thar data store migrator Type=oneshot ExecStart=/usr/bin/migrator --datastore-path /var/lib/thar/datastore/current --migration-directories /var/lib/thar/datastore/migrations --migrate-to-version-from-file /usr/share/thar/data-store-version RemainAfterExit=true +StandardError=journal+console [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/moondog.service b/packages/workspaces/moondog.service index e93ed7581f6..4e97492f038 100644 --- a/packages/workspaces/moondog.service +++ b/packages/workspaces/moondog.service @@ -11,6 +11,7 @@ ConditionPathExists=!/var/lib/thar/moondog.ran Type=oneshot ExecStart=/usr/bin/moondog RemainAfterExit=true +StandardError=journal+console [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/settings-applier.service b/packages/workspaces/settings-applier.service index 3aa45cecac7..d54084e5103 100644 --- a/packages/workspaces/settings-applier.service +++ b/packages/workspaces/settings-applier.service @@ -8,6 +8,7 @@ Wants=settings-committer.service Type=oneshot ExecStart=/usr/bin/thar-be-settings --all RemainAfterExit=true +StandardError=journal+console [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/settings-committer.service b/packages/workspaces/settings-committer.service index c0655325924..c67a1abc3b6 100644 --- a/packages/workspaces/settings-committer.service +++ b/packages/workspaces/settings-committer.service @@ -8,6 +8,7 @@ Wants=storewolf.service sundog.service moondog.service Type=oneshot ExecStart=/usr/bin/settings-committer RemainAfterExit=true +StandardError=journal+console [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/storewolf.service b/packages/workspaces/storewolf.service index 7d15046130f..ef7a541d4cd 100644 --- a/packages/workspaces/storewolf.service +++ b/packages/workspaces/storewolf.service @@ -7,6 +7,7 @@ Requires=migrator.service Type=oneshot ExecStart=/usr/bin/storewolf --data-store-base-path /var/lib/thar/datastore RemainAfterExit=true +StandardError=journal+console [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/sundog.service b/packages/workspaces/sundog.service index 65a8c4d10bd..43e7abfe1ef 100644 --- a/packages/workspaces/sundog.service +++ b/packages/workspaces/sundog.service @@ -8,6 +8,7 @@ Requires=network-online.target apiserver.service Type=oneshot ExecStart=/usr/bin/sundog RemainAfterExit=true +StandardError=journal+console [Install] WantedBy=multi-user.target diff --git a/packages/workspaces/updog.service b/packages/workspaces/updog.service index a355aa922a5..8521b917aad 100644 --- a/packages/workspaces/updog.service +++ b/packages/workspaces/updog.service @@ -4,3 +4,4 @@ Description=What's Updog? [Service] Type=oneshot ExecStart=/usr/bin/updog check-update +StandardError=journal+console