Skip to content

Commit

Permalink
more verbose cli logging command
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj authored and FlorentinDUBOIS committed Jul 13, 2022
1 parent ec9fdf8 commit 3036749
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 25 additions & 2 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ pub enum SubCmd {
},
#[structopt(name = "logging", about = "change logging level")]
Logging {
#[structopt(short = "l", long = "level", help = "change logging level")]
level: String,
// #[structopt(short = "l", long = "level", help = "change logging level")]
#[structopt(subcommand)]
level: LoggingLevel,
},
#[structopt(name = "state", about = "state management")]
State {
Expand Down Expand Up @@ -193,6 +194,28 @@ pub enum MetricsCmd {
Clear,
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum LoggingLevel {
#[structopt(name = "trace", about = "Displays a LOT of logs")]
Trace,
#[structopt(
name = "debug",
about = "Displays more logs about the inner workings of Sōzu"
)]
Debug,
#[structopt(name = "error", about = "Displays occurring errors")]
Error,
#[structopt(name = "warn", about = "Displays warnings about non-critical errors")]
Warn,
#[structopt(name = "info", about = "Displays logs about normal behaviour of Sōzu")]
Info,
}
impl std::fmt::Display for LoggingLevel {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum StateCmd {
#[structopt(name = "save", about = "Save state to that file")]
Expand Down
6 changes: 3 additions & 3 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::MetricsCmd;
use crate::cli::{LoggingLevel, MetricsCmd};
use sozu_command::certificate::{calculate_fingerprint, split_certificate_chain};
use sozu_command::channel::Channel;
use sozu_command::command::{
Expand Down Expand Up @@ -1859,12 +1859,12 @@ pub fn query_metrics(
pub fn logging_filter(
channel: Channel<CommandRequest, CommandResponse>,
timeout: u64,
filter: &str,
filter: &LoggingLevel,
) -> Result<(), anyhow::Error> {
order_command(
channel,
timeout,
ProxyRequestData::Logging(String::from(filter)),
ProxyRequestData::Logging(filter.to_string().to_lowercase()),
)
}

Expand Down

0 comments on commit 3036749

Please sign in to comment.