From 166b1a941be6ca51b10bb38934cc1a7bb44348f3 Mon Sep 17 00:00:00 2001 From: James Rhodes Date: Thu, 16 Jan 2025 17:56:18 +0000 Subject: [PATCH] Add tab completions for `--log-level` --- crates/common/tedge_config/src/cli.rs | 12 ++++++++++++ docs/src/operate/troubleshooting/log-files.md | 15 +++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/common/tedge_config/src/cli.rs b/crates/common/tedge_config/src/cli.rs index c64c4419d5a..8e85e0f5dd9 100644 --- a/crates/common/tedge_config/src/cli.rs +++ b/crates/common/tedge_config/src/cli.rs @@ -3,6 +3,8 @@ use camino::Utf8PathBuf; use clap::Args; use clap::ValueHint; +use clap_complete::ArgValueCandidates; +use clap_complete::CompletionCandidate; /// CLI arguments that should be handled by all thin-edge components. #[derive(Args, Debug, PartialEq, Eq, Clone)] @@ -37,5 +39,15 @@ pub struct LogConfigArgs { /// /// Overrides `--debug` #[clap(long, global = true)] + #[clap(add(ArgValueCandidates::new(log_level_completions)))] pub log_level: Option, } + +fn log_level_completions() -> Vec { + use tracing::Level as L; + let options = [L::TRACE, L::DEBUG, L::INFO, L::WARN, L::ERROR]; + options + .into_iter() + .map(|level| CompletionCandidate::new(level.to_string().to_lowercase())) + .collect() +} diff --git a/docs/src/operate/troubleshooting/log-files.md b/docs/src/operate/troubleshooting/log-files.md index c19e6a0b26d..9503f093505 100644 --- a/docs/src/operate/troubleshooting/log-files.md +++ b/docs/src/operate/troubleshooting/log-files.md @@ -119,19 +119,22 @@ level in `system.toml` ### Setting the log level through cli {#configure-log-levels-cli} -The log level can be enabled for a %%te%% service as below - -For example for tedge-mapper: +The log-level can be configured for a %%te%% service using the `--log-level` +argument. For example for tedge-mapper: ```sh -sudo -u tedge -- tedge-mapper --debug c8y +sudo -u tedge -- tedge-mapper c8y --log-level debug ``` +The possible values for `--log-level` are `trace`, `debug`, `info` (the +default), `warn` and `error`. + :::note -In a similar way it can be set for all the %%te%% services. -Only `debug` level can be set through cli. Also, it enables `trace` level. +In a similar way it can be set for all the %%te%% services and the `tedge` CLI. ::: +There is also a `--debug` argument, which is shorthand for `--log-level debug`. + ### Setting log level through system.toml {#configure-log-levels-file} The log levels can also be configured through the `system.toml` file. The supported log levels are `info, warn, error, trace, debug`.