Skip to content

Commit

Permalink
Rename 'logs' subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Aug 25, 2023
1 parent f7a6e0e commit 7d96623
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 91 deletions.
6 changes: 3 additions & 3 deletions crates/relayer-cli/src/commands/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub mod reset;
#[derive(Command, Debug, Parser, Runnable)]
pub enum LogsCmd {
/// Subcommand used to easily update the lowest log level displayed
LogLevel(log_level::LogLevelCmd),
SetLogLevel(log_level::SetLogLevelCmd),

/// Subcommand used to send a raw directive for log display
Raw(raw::RawCmd),
/// Subcommand used to send a raw filter directive for logs displayed
SetRawFilter(raw::SetRawFilterCmd),

/// Subcommand to restore the log level by using the configuration defined in the config.toml file
Reset(reset::ResetCmd),
Expand Down
68 changes: 10 additions & 58 deletions crates/relayer-cli/src/commands/logs/log_level.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,20 @@
use std::str::FromStr;

use abscissa_core::clap::Parser;
use abscissa_core::Command;
use abscissa_core::Runnable;
use tracing::error;
use tracing::Level;

use crate::error::Error;
use crate::prelude::app_config;
use crate::tracing_handle::send_command;

// TODO use `Level` struct from tracing
// TODO `set-log-level`
#[derive(Clone, Debug, Eq, PartialEq)]
enum LogLevelCommands {
Trace,
Debug,
Info,
Warn,
Error,
}

impl TryInto<String> for LogLevelCommands {
type Error = Error;

fn try_into(self) -> Result<String, Error> {
match self {
LogLevelCommands::Trace => Ok("trace".to_owned()),
LogLevelCommands::Debug => Ok("debug".to_owned()),
LogLevelCommands::Info => Ok("info".to_owned()),
LogLevelCommands::Warn => Ok("warn".to_owned()),
LogLevelCommands::Error => Ok("error".to_owned()),
}
}
}

impl FromStr for LogLevelCommands {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"trace" => Ok(LogLevelCommands::Trace),
"debug" => Ok(LogLevelCommands::Debug),
"info" => Ok(LogLevelCommands::Info),
"warn" => Ok(LogLevelCommands::Warn),
"error" => Ok(LogLevelCommands::Error),
cmd => Err(Error::unknown_log_level(cmd.to_owned())),
}
}
}

#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)]
pub struct LogLevelCmd {
pub struct SetLogLevelCmd {
#[clap(
long = "log-level",
required = true,
value_name = "LOG_LEVEL",
help = "The new lowest log level which will be displayed. Possible values are `trace`, `debug`, `info`, `warn` or `error`"
)]
log_level: LogLevelCommands,
log_level: Level,

#[clap(
long = "log-filter",
Expand All @@ -68,23 +25,18 @@ pub struct LogLevelCmd {
log_filter: Option<String>,
}

impl Runnable for LogLevelCmd {
impl Runnable for SetLogLevelCmd {
fn run(&self) {
let config = app_config();

let port = config.tracing_server.port;

let log_cmd: Result<String, Error> = self.log_level.clone().try_into();
match log_cmd {
Ok(cmd) => {
if let Some(log_filter) = self.log_filter.clone() {
let log_cmd = format!("{log_filter}={cmd}");
send_command(log_cmd, port)
} else {
send_command(cmd, port)
}
}
Err(e) => error!("error: {e}"),
let str_log = self.log_level.clone().to_string();
if let Some(log_filter) = self.log_filter.clone() {
let log_cmd = format!("{log_filter}={str_log}");
send_command(log_cmd, port)
} else {
send_command(str_log, port)
}
}
}
14 changes: 7 additions & 7 deletions crates/relayer-cli/src/commands/logs/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ use crate::tracing_handle::send_command;

// TODO `hermes set-raw-filter`
#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)]
pub struct RawCmd {
pub struct SetRawFilterCmd {
#[clap(
long = "raw-cmd",
long = "raw-filter",
required = true,
value_name = "RAW_CMD",
help = "Raw command used as new tracing directive. Use with caution"
value_name = "RAW_FILTER",
help = "Raw filter used as new tracing directive. Use with caution"
)]
raw_cmd: String,
raw_filter: String,
}

impl Runnable for RawCmd {
impl Runnable for SetRawFilterCmd {
fn run(&self) {
let config = app_config();

let port = config.tracing_server.port;

send_command(self.raw_cmd.clone(), port);
send_command(self.raw_filter.clone(), port);
}
}
8 changes: 4 additions & 4 deletions guide/src/advanced/troubleshooting/log-level.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ __Examples__
The following command is equivalent to running the Hermes instance with `RUST_LOG=ibc=debug hermes start`:

```shell
{{#template ../../templates/commands/hermes/logs/log-level_1.md LOG_LEVEL=debug OPTIONS= --log-filter ibc}}
{{#template ../../templates/commands/hermes/logs/set-log-level_1.md LOG_LEVEL=debug OPTIONS= --log-filter ibc}}
```

It is also possible to only change the `tendermint_rpc` log level:

```shell
{{#template ../../templates/commands/hermes/logs/log-level_1.md LOG_LEVEL=debug OPTIONS= --log-filter tendermint_rpc}}
{{#template ../../templates/commands/hermes/logs/set-log-level_1.md LOG_LEVEL=debug OPTIONS= --log-filter tendermint_rpc}}
```

If the `--log-filter` is not specified, the log level will be set for all targets.
Expand All @@ -146,10 +146,10 @@ The following command is equivalent to running the Hermes instance with `RUST_LO

__Example__

The following command will only display logs which have a field `channel=channel-1` by setting the `<RAW_CMD>` to `"[{channel=channel-1}]"`:
The following command will only display logs which have a field `channel=channel-1` by setting the `<RAW_FILTER>` to `"[{channel=channel-1}]"`:

```shell
{{#template ../../templates/commands/hermes/logs/raw_1.md RAW_CMD=<RAW_CMD>}}
{{#template ../../templates/commands/hermes/logs/set-raw-filter_1.md RAW_FILTER=<RAW_FILTER>}}
```

### Reset command
Expand Down
10 changes: 8 additions & 2 deletions guide/src/documentation/commands/logs/index.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
## Log-level
## Set Log Level

This command allows you to easily update the lowest log level displayed by Hermes.

```shell
{{#include ../../../templates/help_templates/logs/log-level.md}}
```

## Raw
## Set Raw Filter

This command allows you to update the tracing directive used to filter the logs. Please use this command with caution as it requires a precise syntaxe.

```shell
{{#include ../../../templates/help_templates/logs/raw.md}}
```

## Reset

This command will restore the lowest log level displayed using the `log_level` defined in the `config.toml`.

```shell
{{#include ../../../templates/help_templates/logs/reset.md}}
```
1 change: 0 additions & 1 deletion guide/src/templates/commands/hermes/logs/log-level_1.md

This file was deleted.

1 change: 0 additions & 1 deletion guide/src/templates/commands/hermes/logs/raw_1.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[#BINARY hermes]][[#GLOBALOPTIONS]] logs set-log-level[[#OPTIONS]] --log-level [[#LOG_LEVEL]]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[#BINARY hermes]][[#GLOBALOPTIONS]] logs set-raw-filter --raw-filter [[#RAW_FILTER]]
10 changes: 5 additions & 5 deletions guide/src/templates/help_templates/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ OPTIONS:
-h, --help Print help information

SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)
log-level Subcommand used to easily update the lowest log level displayed
raw Subcommand used to send a raw directive for log display
reset Subcommand to restore the log level by using the configuration defined in the
config.toml file
help Print this message or the help of the given subcommand(s)
reset Subcommand to restore the log level by using the configuration defined in
the config.toml file
set-log-level Subcommand used to easily update the lowest log level displayed
set-raw-filter Subcommand used to send a raw filter directive for logs displayed
9 changes: 0 additions & 9 deletions guide/src/templates/help_templates/logs/raw.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DESCRIPTION:
Subcommand used to easily update the lowest log level displayed

USAGE:
hermes logs log-level [OPTIONS] --log-level <LOG_LEVEL>
hermes logs set-log-level [OPTIONS] --log-level <LOG_LEVEL>

OPTIONS:
-h, --help Print help information
Expand Down
9 changes: 9 additions & 0 deletions guide/src/templates/help_templates/logs/set-raw-filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DESCRIPTION:
Subcommand used to send a raw filter directive for logs displayed

USAGE:
hermes logs set-raw-filter --raw-filter <RAW_FILTER>

OPTIONS:
-h, --help Print help information
--raw-filter <RAW_FILTER> Raw filter used as new tracing directive. Use with caution

0 comments on commit 7d96623

Please sign in to comment.