1. Set the run-time setting Log Parameters
In the general log option of run-time setting under the vuser menu of LoadRunner, LoadRunner can define the log operation behavior during script execution. Next we will introduce it one by one:
1. Enable Logging for Enable Logging
If this option is selected, LoadRunner records logs when executing the script. Otherwise, no logs are recorded.
2. Send messages only when an error occurs sends messages when an error occurs.
It is also called JIT (Real-Time) message transmission. logs are written only when an error occurs. After this option is selected, you can set advanced options to specify the log cache size, the default Log Size of LoadRunner is 1 kb.
3. Always send messages
Always send messages
4. Standard log
Standard logs: Create Standard logs for functions and messages sent during script execution for debugging.
Disable this option for large load test scenarios, optimized sessions, or configuration files.
If the logging level is set to "standard", when the script is added to the scenario, session step, or configuration file
The log record mode is automatically set to "send messages only when an error occurs ". However, if the logging mode is disabled or set to "extended", adding the script to the scenario, session step, or configuration file will not affect the logging settings.
5. Extended log ----- parameter substitution
Parameter replacement: select this option to record all parameters specified for the script and their corresponding values.
After the script is parameterized, inserted into transactions, and associated with other optimizations, the parameterized value, the time consumed by the transaction, and the variable values retrieved by the association function are all output in the log, this option plays an important role in checking parameterized values and correct association values in the debugging script.
6. Extended log ----- data returned by Server
Select this option to record all data returned by the server.
LoadRunner records all the response requests sent to the server in the log. From this log, you can check whether the server responds correctly to the request, when using the association value, you often need to view the value to be associated in the log to confirm the left and right boundary of the retrieved data.
7. Extended log ----- advanced trace advanced tracking
Select this option to record all functions and messages sent by the vuser during the session.
This option is useful when debugging vuser scripts.
Ii. Use of log Functions
LoadRunner provides several message functions:
1. lr_message
Int lr_message (const char * format, exp1, exp2,... EXPN .);
The lr_message function sends information to the log file and input window. When running in vugen, the input file is output.txt.
For example:
Char * abort = "aborting ";
Lr_message ("Login Failed: % s", abort );
In the log, you will see: Login Failed: aborting
2. lr_log_message
Int lr_log_message (const char * format, exp1, exp2,... EXPN .);
The lr_log_message function sends messages to the vuser or agent log file (depending on the application) instead of the output window. This function can be used for debugging by sending error messages or other informative messages to log files.
3. lr_error_message
Int lr_error_message (const char * format, exp1, exp2,... EXPN .);
The lr_error_message function sends error messages to the output window and vuser log files.
If run-time Settings> General> miscellaneous> continue on error is not selected, the execution is terminated when the script is executed here. The error level output by this function is high, therefore, if you use this function, select "continue on error ".
4. lr_output_message
Int lr_output_message (const char * format, exp1, exp2,... EXPN .);
The lr_output_message function sends messages with line numbers in the script part to the output window and log files.
3. Define the log output mode in the script
Int lr_debug_message (unsigned int message_level, const char * format ,...);
Explanation: The lr_debug_message function sends a debugging message when the specified message level is active. If the specified message level is not active, no message is sent. You can use the lr_set_debug_message interface to set the active message level to msg_class_brief_log or msg_classs_extended_log. To determine the current level, use lr_get_debug_message.
Unsigned int lr_get_debug_message ();
Explanation: The lr_get_debug_message function returns the current log runtime settings. This setting determines the information sent to the output end. The log settings are specified in the runtime Settings dialog box or by using the lr_set_debug_message function.
Int lr_set_debug_message (unsigned int message_level, unsigned int on_off );
The lr_set_debug_message function sets the message level message_lvl for script execution. By setting the message level, you can determine which messages are sent. The start setting is to pass lr_switch_on as on_off, and to disable the setting is to pass lr_switch_off.
Description of the message_level parameter:
Log Level
C language logo
Value
Runtime-setting-log operation
Disabled
Lr_msg_class_disable_log
0
Disable Enable Logging
Brief
Lr_msg_class_brief_log
1
Select standard log
Extended log
Lr_msg_class_extended_log
16
Select extended log
Result data
Lr_msg_class_result_data
2
Check data returned by Server
Parameter substitution
Lr_msg_class_parameters
4
Select parameter substitution
Full run-time trace
Lr_msg_class_full_trace
8
Select advanced trace
Only on Error
Lr_msg_class_jit_log_on_error
512
Check send messages only when an error occurs
Description of the on_off parameter:
[Lr_switch_on] Enable settings
[Lr_switch_off] disable settings
Let's look at the following small example:
Action ()
{
Int log_leavl;
Log_leavl = lr_get_debug_message ();
Lr_error_message ("Current: % d", log_leavl );
Return 0;
}
When I set only error to print [check send messages only when an error occurs], the running result of the example is: 513 currently; why not 512, I found that I actually chose [Enable Logging + send messages only when an error occurs]. According to the preceding parameter description, it is [1 + 512], that is, 513. Therefore: the number of int returned by lr_get_debug_message is actually the sum of the values of all checked operations!
Let's look at the example set below:
Action ()
{
// Set the log option of runtime-setting. [Enable logging is not checked]
Char *;
A = "ABC ";
Lr_set_debug_message (lr_msg_class_extended_log | lr_msg_class_parameters, lr_switch_on );
// Enable the parameter substitution setting of the runtime-setting log
Lr_debug_message (lr_msg_class_parameters, "Enable system logs saved by Parameters ");
Lr_save_string ("AA", );
Lr_debug_message (lr_msg_class_parameters, "Disable system logs saved by Parameters ");
Lr_set_debug_message (lr_msg_class_extended_log | lr_msg_class_parameters, lr_switch_off );
// Disable the parameter substitution setting of the runtime-setting log
Return 0;
}
Because the runtime-setting does not print any logs, the normal running script should have no log output;
However, the lr_set_debug_message function is used to enable logging settings (output logs for parameter operation saving)
Therefore, when the script runs to lr_save_string ("AA", a), the following logs are output:
Open the System Log saved by the Parameter
Action. C (7): Running Y: Saving parameter "abc = AA"
Disable system logs saved by Parameters