Repository: Orange-OpenSource/hurl
File: packages/hurl/src/runner/hurl_file.rs (Rust)

Code before:
        }
    }
    if let Some(to_entry) = runner_options.to_entry {
        logger.debug(&format!("Executing {to_entry}/{} entries", entries.len()));
    }
}

/// Logs runner `errors`.
/// If we're going to `retry` the entry, we log errors only in verbose. Otherwise, we log error on stderr.
fn log_errors(
    entry_result: &EntryResult,
    content: &str,
    filename: Option<&Input>,
    retry: bool,
    logger: &mut Logger,
) {
    if retry {
        entry_result.errors.iter().for_each(|error| {
            logger.debug_error(content, filename, error, entry_result.source_info);
        });
        return;
    }

    if logger.error_format == ErrorFormat::Long {
        if let Some(Call { response, .. }) = entry_result.calls.last() {
            logger.info("Request can be run with the following curl command:");
            logger.info(&entry_result.curl_cmd.to_string());
            logger.info("");

            response.log_info_all(logger);
        }
    }
    entry_result.errors.iter().for_each(|error| {
        logger.error_runtime_rich(content, filename, error, entry_result.source_info);
    });
}

/// Logs the header indicating the begin of the entry run.
fn log_run_entry(entry_index: usize, logger: &mut Logger) {
    logger.debug_important(
        "------------------------------------------------------------------------------",
    );
    logger.debug_important(&format!("Executing entry {entry_index}"));
}

#[cfg(test)]
mod test {
    use super::*;
    use crate::runner::RunnerOptionsBuilder;

    #[test]

Review comment (suggestion):
@ashishajr Maybe what we can do here is to create a method on `Logger` and use it here?

```rust
pub fn info_curl_cmd(&mut self, cmd: &str) {
        let fmt = self.format();
        let mut s = StyledString::new();
        s.push_with("*", Style::new().blue().bold());
        s.push(" ");
        s.push(cmd);
        self.eprintln(&s.to_string(fmt));
} 
```

I don't like a  lot how we're logging response and we're going to change in the future, hopefully for something better. If think it would be better that all the logging code should be in `logger.rs`. For the moment, there are snippets in various places. We can have some redundancy here given that the code is going to change.

Code after:
        }
    }
    if let Some(to_entry) = runner_options.to_entry {
        logger.debug(&format!("Executing {to_entry}/{} entries", entries.len()));
    }
}

/// Logs runner `errors`.
/// If we're going to `retry` the entry, we log errors only in verbose. Otherwise, we log error on stderr.
fn log_errors(
    entry_result: &EntryResult,
    content: &str,
    filename: Option<&Input>,
    retry: bool,
    logger: &mut Logger,
) {
    if retry {
        entry_result.errors.iter().for_each(|error| {
            logger.debug_error(content, filename, error, entry_result.source_info);
        });
        return;
    }

    if logger.error_format == ErrorFormat::Long {
        if let Some(Call { response, .. }) = entry_result.calls.last() {
            logger.info_curl_cmd(&entry_result.curl_cmd.to_string());
            logger.info("");

            response.log_info_all(logger);
        }
    }
    entry_result.errors.iter().for_each(|error| {
        logger.error_runtime_rich(content, filename, error, entry_result.source_info);
    });
}

/// Logs the header indicating the begin of the entry run.
fn log_run_entry(entry_index: usize, logger: &mut Logger) {
    logger.debug_important(
        "------------------------------------------------------------------------------",
    );
    logger.debug_important(&format!("Executing entry {entry_index}"));
}

#[cfg(test)]
mod test {
    use super::*;
    use crate::runner::RunnerOptionsBuilder;

    #[test]
    fn get_non_default_options_returns_empty_when_default() {