Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rust] Selenium Manager log level #13566

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions rust/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
// specific language governing permissions and limitations
// under the License.

use crate::config::BooleanKey;
use crate::config::{BooleanKey, StringKey};
use crate::metadata::now_unix_timestamp;
use env_logger::Target::Stdout;
use env_logger::DEFAULT_FILTER_ENV;
use log::Level;
use log::LevelFilter::{Debug, Info, Trace};
use log::{Level, LevelFilter};
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::env;
use std::fmt::Display;
use std::ops::Deref;
use std::str::FromStr;

pub const DRIVER_PATH: &str = "Driver path: ";
pub const BROWSER_PATH: &str = "Browser path: ";
Expand Down Expand Up @@ -71,10 +72,11 @@ impl Logger {
pub fn new() -> Self {
let debug = BooleanKey("debug", false).get_value();
let trace = BooleanKey("trace", false).get_value();
Logger::create("", debug, trace)
let log_level = StringKey(vec!["log-level"], "").get_value();
Logger::create("", debug, trace, &log_level)
}

pub fn create(output: &str, debug: bool, trace: bool) -> Self {
pub fn create(output: &str, debug: bool, trace: bool, log_level: &str) -> Self {
let output_type;
if output.eq_ignore_ascii_case("json") {
output_type = OutputType::Json;
Expand All @@ -86,13 +88,18 @@ impl Logger {
match output_type {
OutputType::Logger => {
if env::var(DEFAULT_FILTER_ENV).unwrap_or_default().is_empty() {
let mut filter = match debug {
true => Debug,
false => Info,
let filter = if !log_level.is_empty() {
LevelFilter::from_str(log_level).unwrap_or(Info)
} else {
let mut filter = match debug {
true => Debug,
false => Info,
};
if trace {
filter = Trace;
}
filter
};
if trace {
filter = Trace
}
env_logger::Builder::new()
.filter_module(env!("CARGO_CRATE_NAME"), filter)
.target(Stdout)
Expand Down
7 changes: 6 additions & 1 deletion rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ struct Cli {
#[clap(long)]
trace: bool,

/// Level for output messages. The possible values are: info, debug, trace, warn, error
#[clap(long)]
log_level: Option<String>,

/// Offline mode (i.e., disabling network requests and downloads)
#[clap(long)]
offline: bool,
Expand Down Expand Up @@ -151,7 +155,8 @@ fn main() {

let debug = cli.debug || BooleanKey("debug", false).get_value();
let trace = cli.trace || BooleanKey("trace", false).get_value();
let log = Logger::create(&cli.output, debug, trace);
let log_level = StringKey(vec!["log-level"], &cli.log_level.unwrap_or_default()).get_value();
let log = Logger::create(&cli.output, debug, trace, &log_level);
let grid = cli.grid;
let mut browser_name: String = cli.browser.unwrap_or_default();
let mut driver_name: String = cli.driver.unwrap_or_default();
Expand Down
Loading