pub fn log_debug(
        &self,
        tag: &str,
        request: Option<&SwanlingRequestMetric>,
        headers: Option<&header::HeaderMap>,
        body: Option<&str>,
    ) -> SwanlingTaskResult {
        if !self.config.debug_log.is_empty() {
            // Logger is not defined when running
            // [`test_start`](../struct.SwanlingAttack.html#method.test_start),
            // [`test_stop`](../struct.SwanlingAttack.html#method.test_stop), and during testing.
            if let Some(logger) = self.logger.clone() {
                if self.config.no_debug_body {
                    logger.send(Some(SwanlingLog::Debug(SwanlingDebug::new(
                        tag, request, headers, None,
                    ))))?;
                } else {
                    logger.send(Some(SwanlingLog::Debug(SwanlingDebug::new(
                        tag, request, headers, body,
                    ))))?;
                }
            }
        }

        Ok(())
    }
/// Write to [`debug_file`](../struct.SwanlingConfiguration.html#structfield.debug_file)
/// if enabled.
///
/// This function provides a mechanism for optional debug logging when a load test
/// is running. This can be especially helpful when writing a load test. Each entry
/// must include a tag, which is an arbitrary string identifying the debug message.
/// It may also optionally include references to the SwanlingRequestMetric made, the headers
/// returned by the server, and the response body returned by the server,
///
/// As the response body can be large, the `--no-debug-body` option (or
/// [`SwanlingDefault::NoDebugBody`](../enum.SwanlingDefault.html#variant.NoDebugBody) default)
/// can be set to prevent the debug log from including the response body. When this option
/// is enabled, the body will always show up as `null` in the debug log.
///
/// Calls to
/// [`set_failure`](https://docs.rs/swanling/*/swanling/swanling/struct.SwanlingUser.html#method.set_failure)
/// automatically invoke `log_debug`.
///
/// To enable the debug log, a load test must be run with the `--debug-log-file=foo`
/// option set, where `foo` is either a relative or an absolute path of the log file
/// to create. Any existing file will be overwritten.
///
/// In the following example, we are logging debug messages whenever there are errors.
///
/// # Example
/// ```rust
/// use swanling::prelude::*;
///
/// let mut task = task!(loadtest_index_page);
///
/// async fn loadtest_index_page(user: &SwanlingUser) -> SwanlingTaskResult {
///     let mut swanling = user.get("/").await?;
///
///     match swanling.response {
///         Ok(response) => {
///             // Grab a copy of the headers so we can include them when logging errors.
///             let headers = &response.headers().clone();
///             // We only need to check pages that returned a success status code.
///             if !response.status().is_success() {
///                 match response.text().await {
///                     Ok(html) => {
///                         // Server returned an error code, log everything.
///                         user.log_debug(
///                             "error loading /",
///                             Some(&swanling.request),
///                             Some(headers),
///                             Some(&html),
///                         );
///                     },
///                     Err(e) => {
///                         // No body was returned, log everything else.
///                         user.log_debug(
///                             &format!("error loading /: {}", e),
///                             Some(&swanling.request),
///                             Some(headers),
///                             None,
///                         );
///                     }
///                 }
///             }
///         },
///         // No response from server.
///         Err(e) => {
///             user.log_debug(
///                 "no response from server when loading /",
///                 Some(&swanling.request),
///                 None,
///                 None,
///             );
///         }
///     }
///
///     Ok(())
/// }
/// ````


This function provides a mechanism for optional debug logging when a load test
is running. This can be especially helpful when writing a load test. Each entry
must include a tag, which is an arbitrary string identifying the debug message.
It may also optionally include references to the SwanlingRequestMetric made, the headers
returned by the server, and the response body returned by the server.

As the response body can be large, the `--no-debug-body` option (or
[`SwanlingDefault::NoDebugBody`](../enum.SwanlingDefault.html#variant.NoDebugBody) default)
can be set to prevent the debug log from including the response body. When this option
is enabled, the body will always show up as `null` in the debug log.



To enable the debug log, a load test must be run with the `--debug-log-file=foo`
option set, where `foo` is either a relative or an absolute path of the log file
to create. Any existing file will be overwritten.

In the following example, we are logging debug messages whenever there are errors.
This function provides a mechanism for optional debug logging when a load test is running . This can be especially helpful when writing a load test . Each entry must include a tag which is an arbitrary string identifying the debug message . It may also optionally include references to the SwanlingRequestMetric made the headers returned by the server and the response body returned by the server . As the response body can be large the ` -- no - debug - body ` option ( or [ ` SwanlingDefault :: NoDebugBody ` ] ( .. / enum . SwanlingDefault . html#variant . NoDebugBody ) default ) can be set to prevent the debug log from including the response body . When this option is enabled the body will always show up as ` null ` in the debug log . To enable the debug log a load test must be run with the ` -- debug - log - file = foo ` option set where ` foo ` is either a relative or an absolute path of the log file to create . Any existing file will be overwritten . In the following example we are logging debug messages whenever there are errors .
pub fn log_debug(
        &self,
        tag: &str,
        request: Option<&SwanlingRequestMetric>,
        headers: Option<&header::HeaderMap>,
        body: Option<&str>,
    ) -> SwanlingTaskResult {
        if !self.config.debug_log.is_empty() {
            // Logger is not defined when running
            // [`test_start`](../struct.SwanlingAttack.html#method.test_start),
            // [`test_stop`](../struct.SwanlingAttack.html#method.test_stop), and during testing.
            if let Some(logger) = self.logger.clone() {
                if self.config.no_debug_body {
                    logger.send(Some(SwanlingLog::Debug(SwanlingDebug::new(
                        tag, request, headers, None,
                    ))))?;
                } else {
                    logger.send(Some(SwanlingLog::Debug(SwanlingDebug::new(
                        tag, request, headers, body,
                    ))))?;
                }
            }
        }
        Ok(())
    }
pub fn log_debug ( & self , tag : & str , request : Option < & SwanlingRequestMetric > , headers : Option < & header :: HeaderMap > , body : Option < & str > , ) -> SwanlingTaskResult { if ! self . config . debug_log . is_empty ( ) { // Logger is not defined when running // [`test_start`](../struct.SwanlingAttack.html#method.test_start), // [`test_stop`](../struct.SwanlingAttack.html#method.test_stop), and during testing. if let Some ( logger ) = self . logger . clone ( ) { if self . config . no_debug_body { logger . send ( Some ( SwanlingLog :: Debug ( SwanlingDebug :: new ( tag , request , headers , None , ) ) ) ) ? ; } else { logger . send ( Some ( SwanlingLog :: Debug ( SwanlingDebug :: new ( tag , request , headers , body , ) ) ) ) ? ; } } } Ok ( ( ) ) }
Write to [`debug_file`](../struct.SwanlingConfiguration.html#structfield.debug_file)
if enabled.
Write to [ ` debug_file ` ] ( .. / struct . SwanlingConfiguration . html#structfield . debug_file ) if enabled .
&self
tag
&str
request
Option<&SwanlingRequestMetric>
headers
Option<&header::HeaderMap>
body
Option<&str>
example
```rust
use swanling::prelude::*.

let mut task = task!(loadtest_index_page).

async fn loadtest_index_page(user: &SwanlingUser) -> SwanlingTaskResult {
let mut swanling = user.get("/").await?.

match swanling.response {
Ok(response) => {
Grab a copy of the headers so we can include them when logging errors.
let headers = &response.headers().clone();
We only need to check pages that returned a success status code.
if !response.status().is_success() {
match response.text().await {
Ok(html) => {
Server returned an error code, log everything.
user.log_debug(
"error loading /",
Some(&swanling.request),
Some(headers),
Some(&html),
);
},
Err(e) => {
No body was returned, log everything else.
user.log_debug(
&format!("error loading /: {}", e),
Some(&swanling.request),
Some(headers),
None,
);
}
}
}
},
No response from server.
Err(e) => {
user.log_debug(
"no response from server when loading /",
Some(&swanling.request),
None,
None,
);
}
}


` ` ` rust use swanling :: prelude :: * . let mut task = task! ( loadtest_index_page ) . async fn loadtest_index_page ( user : &SwanlingUser ) - > SwanlingTaskResult { let mut swanling = user . get ( " / " ) . await? . match swanling . response { Ok ( response ) = > { Grab a copy of the headers so we can include them when logging errors . let headers = &response . headers () . clone () ; We only need to check pages that returned a success status code . if !response . status () . is_success () { match response . text () . await { Ok ( html ) = > { Server returned an error code log everything . user . log_debug ( " error loading / " Some ( &swanling . request ) Some ( headers ) Some ( &html ) ) ; } Err ( e ) = > { No body was returned log everything else . user . log_debug ( &format! ( " error loading / : {} " e ) Some ( &swanling . request ) Some ( headers ) None ) ; } } } } No response from server . Err ( e ) = > { user . log_debug ( " no response from server when loading / " Some ( &swanling . request ) None None ) ; } }