This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/master by this push:
     new c1c4093  Polish the logging logics and document the usages (#385)
c1c4093 is described below

commit c1c40930146d71bc423d2bec93ec92508616bca0
Author: Mingshen Sun <[email protected]>
AuthorDate: Mon Jul 6 15:18:31 2020 -0700

    Polish the logging logics and document the usages (#385)
---
 docs/development-tips.md                        | 24 ++++++++++++++++++++++++
 services/access_control/app/src/main.rs         |  6 +++++-
 services/authentication/app/src/main.rs         |  6 +++++-
 services/execution/app/src/main.rs              |  6 +++++-
 services/frontend/app/src/main.rs               |  6 +++++-
 services/management/app/src/main.rs             |  6 +++++-
 services/scheduler/app/src/main.rs              |  6 +++++-
 services/storage/app/src/main.rs                |  6 +++++-
 services/utils/service_enclave_utils/src/lib.rs |  6 +++++-
 tests/functional/app/src/main.rs                |  6 +++++-
 tests/integration/app/src/main.rs               |  6 +++++-
 tests/unit/app/src/main.rs                      |  6 +++++-
 tool/app/src/main.rs                            |  6 +++++-
 13 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/docs/development-tips.md b/docs/development-tips.md
index a5fde59..361cf3b 100644
--- a/docs/development-tips.md
+++ b/docs/development-tips.md
@@ -27,3 +27,27 @@ root directory as `Cargo.toml`. For standalone Rust 
applications such as CLI, no
 `Cargo.toml` is needed. After the preparation of `Cargo.toml` in root,
 RLS/rust-analyzer can understand the projects finally. You will see type hints
 and cross references using IDEs with extensions.
+
+## Logging
+
+Teaclave utilizes the [`env_logger`](https://github.com/sebasmagri/env_logger/)
+crate to configure the display of *debug logs* via environment variables.
+
+Logging is controlled via the `TEACLAVE_LOG` environment variables and the 
value
+of this variable is a comma-separated list of logging directives in the
+`parth::to::module=level` form. For example, you can set the environment
+`TEACLAVE_LOG=attestation=debug` before launching a service to print the debug
+level (and higher-level) logs in the `attestation` module to stdout/stderr.
+There are five logging levels: `error`, `warn`, `info`, `debug` and `trace`
+where error represents the highest-priority log level. Furthermore, you can 
also
+filter the results with regular expression by simply put `/` followed by a 
regex
+in the directives in the environment variable. You can find more filter usages
+in the `env_logger`'s
+[document](https://docs.rs/env_logger/0.7.1/env_logger/index.html#filtering-results).
+
+
+::: tip NOTE
+To prevent sensitive information leakage through logging, for the release 
build,
+we disable all logging (at build time) lower than the `info` level. That is,
+only `error`, `warn` and `info` logs will be printed.
+:::
diff --git a/services/access_control/app/src/main.rs 
b/services/access_control/app/src/main.rs
index d6e0127..f4a66dc 100644
--- a/services/access_control/app/src/main.rs
+++ b/services/access_control/app/src/main.rs
@@ -24,7 +24,11 @@ use teaclave_service_app_utils::{register_signals, 
TeaclaveServiceLauncher};
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
 fn main() -> Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
 
     let launcher = Arc::new(TeaclaveServiceLauncher::new(
         PACKAGE_NAME,
diff --git a/services/authentication/app/src/main.rs 
b/services/authentication/app/src/main.rs
index d6e0127..f4a66dc 100644
--- a/services/authentication/app/src/main.rs
+++ b/services/authentication/app/src/main.rs
@@ -24,7 +24,11 @@ use teaclave_service_app_utils::{register_signals, 
TeaclaveServiceLauncher};
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
 fn main() -> Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
 
     let launcher = Arc::new(TeaclaveServiceLauncher::new(
         PACKAGE_NAME,
diff --git a/services/execution/app/src/main.rs 
b/services/execution/app/src/main.rs
index 4e5799b..0a67c24 100644
--- a/services/execution/app/src/main.rs
+++ b/services/execution/app/src/main.rs
@@ -27,7 +27,11 @@ pub use teaclave_file_agent::ocall_handle_file_request;
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
 fn main() -> Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
 
     let launcher = Arc::new(TeaclaveServiceLauncher::new(
         PACKAGE_NAME,
diff --git a/services/frontend/app/src/main.rs 
b/services/frontend/app/src/main.rs
index d6e0127..f4a66dc 100644
--- a/services/frontend/app/src/main.rs
+++ b/services/frontend/app/src/main.rs
@@ -24,7 +24,11 @@ use teaclave_service_app_utils::{register_signals, 
TeaclaveServiceLauncher};
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
 fn main() -> Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
 
     let launcher = Arc::new(TeaclaveServiceLauncher::new(
         PACKAGE_NAME,
diff --git a/services/management/app/src/main.rs 
b/services/management/app/src/main.rs
index d6e0127..f4a66dc 100644
--- a/services/management/app/src/main.rs
+++ b/services/management/app/src/main.rs
@@ -24,7 +24,11 @@ use teaclave_service_app_utils::{register_signals, 
TeaclaveServiceLauncher};
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
 fn main() -> Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
 
     let launcher = Arc::new(TeaclaveServiceLauncher::new(
         PACKAGE_NAME,
diff --git a/services/scheduler/app/src/main.rs 
b/services/scheduler/app/src/main.rs
index d6e0127..f4a66dc 100644
--- a/services/scheduler/app/src/main.rs
+++ b/services/scheduler/app/src/main.rs
@@ -24,7 +24,11 @@ use teaclave_service_app_utils::{register_signals, 
TeaclaveServiceLauncher};
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
 fn main() -> Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
 
     let launcher = Arc::new(TeaclaveServiceLauncher::new(
         PACKAGE_NAME,
diff --git a/services/storage/app/src/main.rs b/services/storage/app/src/main.rs
index d6e0127..f4a66dc 100644
--- a/services/storage/app/src/main.rs
+++ b/services/storage/app/src/main.rs
@@ -24,7 +24,11 @@ use teaclave_service_app_utils::{register_signals, 
TeaclaveServiceLauncher};
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
 fn main() -> Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
 
     let launcher = Arc::new(TeaclaveServiceLauncher::new(
         PACKAGE_NAME,
diff --git a/services/utils/service_enclave_utils/src/lib.rs 
b/services/utils/service_enclave_utils/src/lib.rs
index 0faba96..2f938ab 100644
--- a/services/utils/service_enclave_utils/src/lib.rs
+++ b/services/utils/service_enclave_utils/src/lib.rs
@@ -46,7 +46,11 @@ pub struct ServiceEnclave;
 
 impl ServiceEnclave {
     pub fn init(name: &str) -> teaclave_types::TeeServiceResult<()> {
-        env_logger::init();
+        env_logger::init_from_env(
+            env_logger::Env::new()
+                .filter_or("TEACLAVE_LOG", "RUST_LOG")
+                .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+        );
 
         debug!("Enclave initializing");
 
diff --git a/tests/functional/app/src/main.rs b/tests/functional/app/src/main.rs
index 6c43e9f..a4854bf 100644
--- a/tests/functional/app/src/main.rs
+++ b/tests/functional/app/src/main.rs
@@ -30,7 +30,11 @@ struct Cli {
 
 fn main() -> anyhow::Result<()> {
     let args = Cli::from_args();
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
     let tee = TeeBinder::new(env!("CARGO_PKG_NAME"))?;
     start_enclave_unit_test_driver(&tee, args.test_names)?;
     tee.finalize();
diff --git a/tests/integration/app/src/main.rs 
b/tests/integration/app/src/main.rs
index 0076e8c..4bfecde 100644
--- a/tests/integration/app/src/main.rs
+++ b/tests/integration/app/src/main.rs
@@ -21,7 +21,11 @@ use teaclave_binder::TeeBinder;
 use teaclave_types::TeeServiceResult;
 
 fn main() -> anyhow::Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
     let tee = TeeBinder::new(env!("CARGO_PKG_NAME"))?;
     run(&tee)?;
     tee.finalize();
diff --git a/tests/unit/app/src/main.rs b/tests/unit/app/src/main.rs
index f04302e..13b5b12 100644
--- a/tests/unit/app/src/main.rs
+++ b/tests/unit/app/src/main.rs
@@ -23,7 +23,11 @@ use teaclave_types::TeeServiceResult;
 pub use teaclave_file_agent::ocall_handle_file_request;
 
 fn main() -> anyhow::Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
     let tee = TeeBinder::new(env!("CARGO_PKG_NAME"))?;
     run(&tee)?;
     tee.finalize();
diff --git a/tool/app/src/main.rs b/tool/app/src/main.rs
index cad1d0c..e76376c 100644
--- a/tool/app/src/main.rs
+++ b/tool/app/src/main.rs
@@ -24,7 +24,11 @@ use teaclave_binder::TeeBinder;
 use teaclave_types::TeeServiceResult;
 
 fn attestation(opt: &AttestationOpt) -> anyhow::Result<()> {
-    env_logger::init();
+    env_logger::init_from_env(
+        env_logger::Env::new()
+            .filter_or("TEACLAVE_LOG", "RUST_LOG")
+            .write_style_or("TEACLAVE_LOG_STYLE", "RUST_LOG_STYLE"),
+    );
     let tee = TeeBinder::new(env!("CARGO_PKG_NAME"))?;
     run(&tee, opt)?;
     tee.finalize();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to