Expand description
An optional thread for writing logs.
Goose can generate a number of log files during a load test, enabled through any combination of the following run time options:
--debug-log
,--request-log
,--transaction-log
,--scenario-log
It’s also possible to configure the format of any of thse logs to be json
, csv
, or raw
(the standard debug output of a Rust structure), using the following run time optios:
--debug-format
,--request-format
,--transaction-format
,--scenario-format
All of these loggers use a single shared logger thread, with
GooseUser
s sending log messages through the same shared
channel. The logger determines which log file to write the message to based on the message
data type. The logger thread uses Tokio’s asynchronous
BufWriter
. The logger thread only
starts if at least one logger is enabled.
Note: there’s also a --goose-log
run time option which records any errors or messages
generated by Goose while running a load test. This functionality is not implemented in this
file.
Request File logger
The Goose requests logger is enabled with the --request-log
command-line option, or the
GooseDefault::RequestLog
default
configuration option. The format of the log is configured with the --request-format
command-line option, or the
GooseDefault::RequestFormat
default
configuration option.
Each GooseRequestMetric
object generated by all GooseUser
threads during a load test is written to this log file.
Transaction File logger
The Goose transactions logger is enabled with the --transaction-log
command-line option, or the
GooseDefault::TransactionLog
default
configuration option. The format of the log is configured with the --transaction-format
command-line option, or the
GooseDefault::TransactionFormat
default
configuration option.
Each TransactionMetric
object generated by all GooseUser
threads during a load test is written to this log file.
Scenario File logger
The Goose scenarios logger is enabled with the --scenario-log
command-line option, or the
GooseDefault::ScenarioLog
default
configuration option. The format of the log is configured with the --scenario-format
command-line option, or the
GooseDefault::ScenarioFormat
default
configuration option.
Each ScenarioMetric
object generated by all GooseUser
threads during a load test is written to this log file.
Debug File logger
The Goose debug logger is enabled with the --debug-log
command-line option, or the
GooseDefault::DebugLog
default
configuration option.
Each GooseDebug
object generated by all GooseUser
threads during a load test is written to this log file.
Writing Debug Logs
Logs can be sent to the logger thread by invoking
log_debug
from load test transaction functions.
Calls to
set_failure
automatically invoke
log_debug
.
Most of the included examples showing how to use the debug logger include a copy of the request made, the response headers returned by the server, and the response body. It can also be used to log arbitrary information, for example if you want to record everything you sent via a POST to a form.
use goose::prelude::*;
let mut transaction = transaction!(post_to_form);
async fn post_to_form(user: &mut GooseUser) -> TransactionResult {
let path = "/path/to/form";
let params = [
("field_1", "foo"),
("field_2", "bar"),
("op", "Save"),
];
// Only log the form parameters we will post.
user.log_debug(
&format!("POSTing {:?} on {}", ¶ms, path),
None,
None,
None,
)?;
let goose = user.post_form(path, ¶ms).await?;
// Log the form parameters that were posted together with details about the entire
// request that was sent to the server.
user.log_debug(
&format!("POSTing {:#?} on {}", ¶ms, path),
Some(&goose.request),
None,
None,
)?;
Ok(())
}
The first call to
log_debug
results in a debug log message similar to:
{"body":null,"header":null,"request":null,"tag":"POSTing [(\"field_1\", \"foo\"), (\"field_2\", \"bar\"), (\"op\", \"Save\")] on /path/to/form"}
The second call to
log_debug
results in a debug log message similar to:
{"body":null,"header":null,"request":{"elapsed":1,"final_url":"http://local.dev/path/to/form","method":"POST","name":"(Anon) post to form","redirected":false,"response_time":22,"status_code":404,"success":false,"update":false,"url":"http://local.dev/path/to/form","user":0},"tag":"POSTing [(\"field_1\", \"foo\"), (\"field_2\", \"bar\"), (\"op\", \"Save\")] on /path/to/form"}
For a more complex debug logging example, refer to the
log_debug
documentation.
Reducing File And Memory Usage
The debug logger can result in a very large debug file, as by default it includes the
entire body of any pages returned that result in an error. This also requires allocating
a bigger BufWriter
, and can
generate a lot of disk io.
If you don’t need to log response bodies, you can disable this functionality (and reduce
the amount of RAM required by the
BufWriter
by setting the
--no-debug-body
command-line option, or the
GooseDefault::NoDebugBody
default
configuration option. The debug logger will still record any custom messages, details
about the request (when available), and all server response headers (when available).
Re-exports
pub use format_csv_row;
Enums
- If enabled, the logger thread can accept any of the following types of messages, and will write them to the correct log file.
- Defines the formats logs can be written to file.