LoadRunner如何在脚本运行时修改log设置选项
LoadRunner如何在脚本运行时修改log设置选项?答案是使用lr_set_debug_message函数:
lr_set_debug_message
Sets the message level for the script execution.
int lr_set_debug_message (unsigned int message_level, unsigned int on_off);
例子:
lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_FULL_TRACE, LR_SWITCH_ON );
rc = lrd_fetch(Csr1, 1, 1, 0, PrintRow3);
if (rc>2000)
lr_debug_message(LR_MSG_CLASS_FULL_TRACE,
"Fetch failed returned %d", rc);
/* Now reset message class to former level */
lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_FULL_TRACE, LR_SWITCH_OFF );
参数message_level的设置与LR的run-time设置界面中的选项有对应关系,可参考下表以及LR的帮助文档:
Each logging option has a C-constant that is a binary value with a 1 in the position that corresponds to the log option.
Log Level |
C Constant |
Value |
Binary Value |
Disabled |
LR_MSG_CLASS_DISABLE_LOG |
0 |
00000000 00000000 |
Brief |
LR_MSG_CLASS_BRIEF_LOG |
1 |
00000000 00000001 |
Extended Log |
LR_MSG_CLASS_EXTENDED_LOG |
16 |
00000000 00010000 |
Result Data |
LR_MSG_CLASS_RESULT_DATA |
2 |
00000000 00000010 |
Parameter Substitution |
LR_MSG_CLASS_PARAMETERS |
4 |
00000000 00000100 |
Full Run-Time Trace |
LR_MSG_CLASS_FULL_TRACE |
8 |
00000000 00001000 |
Log on Error |
LR_MSG_CLASS_JIT_LOG_ON_ERROR |
512 |
00000010 00000000 |
在脚本动态设置log选项前,可以采用下面的函数来清空已有的设置:
// Turn off all logging options (this is the same as having logging disabled).
void jds_clear_log_options(void) {
unsigned int log_options = lr_get_debug_message();
lr_set_debug_message(log_options, LR_SWITCH_OFF);
return;
}
脚本中使用了lr_get_debug_message函数来取得当前的设置。
参考: