diff --git a/crates/relayer-cli/src/commands/logs.rs b/crates/relayer-cli/src/commands/logs.rs index d8c306c6e3..2a55b2a8f1 100644 --- a/crates/relayer-cli/src/commands/logs.rs +++ b/crates/relayer-cli/src/commands/logs.rs @@ -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), diff --git a/crates/relayer-cli/src/commands/logs/log_level.rs b/crates/relayer-cli/src/commands/logs/log_level.rs index a11df34d3c..605b7fd87c 100644 --- a/crates/relayer-cli/src/commands/logs/log_level.rs +++ b/crates/relayer-cli/src/commands/logs/log_level.rs @@ -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 for LogLevelCommands { - type Error = Error; - - fn try_into(self) -> Result { - 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 { - 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", @@ -68,23 +25,18 @@ pub struct LogLevelCmd { log_filter: Option, } -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 = 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) } } } diff --git a/crates/relayer-cli/src/commands/logs/raw.rs b/crates/relayer-cli/src/commands/logs/raw.rs index 225f6878aa..c3fae4f43f 100644 --- a/crates/relayer-cli/src/commands/logs/raw.rs +++ b/crates/relayer-cli/src/commands/logs/raw.rs @@ -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); } } diff --git a/guide/src/advanced/troubleshooting/log-level.md b/guide/src/advanced/troubleshooting/log-level.md index f1eb750d9a..c8edb886c0 100644 --- a/guide/src/advanced/troubleshooting/log-level.md +++ b/guide/src/advanced/troubleshooting/log-level.md @@ -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. @@ -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 `` to `"[{channel=channel-1}]"`: +The following command will only display logs which have a field `channel=channel-1` by setting the `` to `"[{channel=channel-1}]"`: ```shell - {{#template ../../templates/commands/hermes/logs/raw_1.md RAW_CMD=}} + {{#template ../../templates/commands/hermes/logs/set-raw-filter_1.md RAW_FILTER=}} ``` ### Reset command diff --git a/guide/src/documentation/commands/logs/index.md b/guide/src/documentation/commands/logs/index.md index d7298524cb..cb94477a5c 100644 --- a/guide/src/documentation/commands/logs/index.md +++ b/guide/src/documentation/commands/logs/index.md @@ -1,10 +1,14 @@ -## 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}} @@ -12,6 +16,8 @@ ## 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}} ``` \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/logs/log-level_1.md b/guide/src/templates/commands/hermes/logs/log-level_1.md deleted file mode 100644 index 79c80fb321..0000000000 --- a/guide/src/templates/commands/hermes/logs/log-level_1.md +++ /dev/null @@ -1 +0,0 @@ -[[#BINARY hermes]][[#GLOBALOPTIONS]] logs log-level[[#OPTIONS]] --log-level [[#LOG_LEVEL]] \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/logs/raw_1.md b/guide/src/templates/commands/hermes/logs/raw_1.md deleted file mode 100644 index 4d4a537bb5..0000000000 --- a/guide/src/templates/commands/hermes/logs/raw_1.md +++ /dev/null @@ -1 +0,0 @@ -[[#BINARY hermes]][[#GLOBALOPTIONS]] logs raw --raw-cmd [[#RAW_CMD]] \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/logs/set-log-level_1.md b/guide/src/templates/commands/hermes/logs/set-log-level_1.md new file mode 100644 index 0000000000..5485b576de --- /dev/null +++ b/guide/src/templates/commands/hermes/logs/set-log-level_1.md @@ -0,0 +1 @@ +[[#BINARY hermes]][[#GLOBALOPTIONS]] logs set-log-level[[#OPTIONS]] --log-level [[#LOG_LEVEL]] \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/logs/set-raw-filter_1.md b/guide/src/templates/commands/hermes/logs/set-raw-filter_1.md new file mode 100644 index 0000000000..eeabc079e5 --- /dev/null +++ b/guide/src/templates/commands/hermes/logs/set-raw-filter_1.md @@ -0,0 +1 @@ +[[#BINARY hermes]][[#GLOBALOPTIONS]] logs set-raw-filter --raw-filter [[#RAW_FILTER]] \ No newline at end of file diff --git a/guide/src/templates/help_templates/logs.md b/guide/src/templates/help_templates/logs.md index 17dff28973..632c623449 100644 --- a/guide/src/templates/help_templates/logs.md +++ b/guide/src/templates/help_templates/logs.md @@ -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 diff --git a/guide/src/templates/help_templates/logs/raw.md b/guide/src/templates/help_templates/logs/raw.md deleted file mode 100644 index 61c9373480..0000000000 --- a/guide/src/templates/help_templates/logs/raw.md +++ /dev/null @@ -1,9 +0,0 @@ -DESCRIPTION: -Subcommand used to send a raw directive for log display - -USAGE: - hermes logs raw --raw-cmd - -OPTIONS: - -h, --help Print help information - --raw-cmd Raw command used as new tracing directive. Use with caution diff --git a/guide/src/templates/help_templates/logs/log-level.md b/guide/src/templates/help_templates/logs/set-log-level.md similarity index 89% rename from guide/src/templates/help_templates/logs/log-level.md rename to guide/src/templates/help_templates/logs/set-log-level.md index cf69dc3bed..13aa7450fb 100644 --- a/guide/src/templates/help_templates/logs/log-level.md +++ b/guide/src/templates/help_templates/logs/set-log-level.md @@ -2,7 +2,7 @@ DESCRIPTION: Subcommand used to easily update the lowest log level displayed USAGE: - hermes logs log-level [OPTIONS] --log-level + hermes logs set-log-level [OPTIONS] --log-level OPTIONS: -h, --help Print help information diff --git a/guide/src/templates/help_templates/logs/set-raw-filter.md b/guide/src/templates/help_templates/logs/set-raw-filter.md new file mode 100644 index 0000000000..e65a60bc78 --- /dev/null +++ b/guide/src/templates/help_templates/logs/set-raw-filter.md @@ -0,0 +1,9 @@ +DESCRIPTION: +Subcommand used to send a raw filter directive for logs displayed + +USAGE: + hermes logs set-raw-filter --raw-filter + +OPTIONS: + -h, --help Print help information + --raw-filter Raw filter used as new tracing directive. Use with caution