LoadRunner如何在指令碼執行時修改log設定選項?

TIB發表於2010-01-24

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的設定與LRrun-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函式來取得當前的設定。

 

 

參考:

http://www.jds.net.au/tech-tips/loadrunner-log-options/

相關文章