Skip to content

Commit

Permalink
Add tab completions for --log-level
Browse files Browse the repository at this point in the history
  • Loading branch information
jarhodes314 committed Jan 16, 2025
1 parent 1cf7710 commit 166b1a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 12 additions & 0 deletions crates/common/tedge_config/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -37,5 +39,15 @@ pub struct LogConfigArgs {
///
/// Overrides `--debug`
#[clap(long, global = true)]
#[clap(add(ArgValueCandidates::new(log_level_completions)))]
pub log_level: Option<tracing::Level>,
}

fn log_level_completions() -> Vec<CompletionCandidate> {
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()
}
15 changes: 9 additions & 6 deletions docs/src/operate/troubleshooting/log-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 166b1a9

Please sign in to comment.