lr_set_debug_message

In this Loadrunner Tutorial, you will learn about lr_set_debug_message. By using lr_set_debug_message() function we can set the log options in the vuser script in the script itself without going to runtime setting.

In order to use this function we need to use lr_set_debug_message function before the code in Action() method and close as per requirement.

Let us see the following code format to understand it better. This is how we use this function inside action which can be shown as given below.

Action()

{

lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG, LR_SWITCH_ON);

——————————————————

——————————————————-

—————————————————–

lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG, LR_SWITCH_OFF);

return 0;

}

So, we can say that we can change the log level or message level for the script means output log will be generated based on the log level defined by this function

int lr_set_debug_message( unsigned int message_level_flag, unsigned int on_off );

Arguments

message_level_flag       One of the Message Log Runtime Settings which we can be seen as, given below

on_off  A switch to activate or deactivate message level setting. We use any one among On-Off Constants.It is just for enabling or disabling the log.

Let us see some of the settings available in runtime setting of LoadRunner , where we can see that there is option of disabling log,  getting standard log or getting extended log , which will focus on particular type of log depending on type of log selected.We can clearly see that there are three types of extended log, which we use them depending on our requirement which is also given in the screenshot given below.

lr_set_debug_message function in Loadrunner

Let us see one example to understand it in better way, as given below.

Action()

{

//Declaring variable

int rc;

//Setting extended log with advanced resorption advance trace option which we can see in the screenshot above as well.

lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_FULL_TRACE, LR_SWITCH_ON );

//Saving value in parameter

lr_save_string(“1000”, “prmCounter”);

//Printing value of the parameter in the output log window of loadrunner

lr_output_message(“String value of prmCounter: %s”, lr_eval_string(“{prmCounter}”));

//Converting string value of the parameter to integer value and assigning lead to new variable assigning it to new variable  rc

rc = atoi(lr_eval_string(“{prmCounter}”));

//Printing the value contained in the variable

lr_output_message(“Integer value of prmCounter: %d”, rc);

if (rc>2000)

//Printing dottrace message

Printing the trace map message in the output log window of loadrunner if condition satisfied is satisfied

lr_debug_message(LR_MSG_CLASS_FULL_TRACE, “Fetch failed returned %d”, rc);

//This is Bling disabling extended log with advance case trace

lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_FULL_TRACE, LR_SWITCH_OFF );

                return 0;

}

Let us see the same code in LoadRunner window, in the form of screenshot given below.

lr_set_debug_message function in Loadrunner with Examples

Using the code given above, we have changed runtime setting, as given below in the form of a screenshot where Extended Log has been enabled and Advance Trace option is also enabled, which is available after extended log is selected.

lr_set_debug_message Extended Log

We can clearly see the output of Advance Trace option of Extended Log which is given as below. Highlighted message in the output log window of LoadRunner (which is given as below) is full trace message generated by the code/ script

Output of the above executed program is given below.

Starting action Action.

Action.c(6): String value of prmCounter: 3000

Action.c(9): Integer value of prmCounter: 3000

Fetch failed returned 3000

Ending action Action.

Let us see another code given below to understand the concept in more better way. In this code, we are first getting current time setting through the function lr_get_debug_message, which has been done in LoadRunner and then from the script itself, we are changing the runtime setting and here we are disabling the log using the function lr_set_debug_message. Let us see the script as given below.

Action()

{

unsigned int n = lr_get_debug_message();  

// get the current log level

lr_output_message(“The current level is %d”, n);

// this message is written to the log

lr_set_debug_message(n, LR_SWITCH_OFF);  

// clear all flags

lr_set_debug_message(LR_MSG_CLASS_JIT_LOG_ON_ERROR, LR_SWITCH_ON);

// set the log level to JIT

  lr_output_message(“This message will not appear in output log window of LoadRunner”);

lr_message(“%s”, “This message will not appear in output log window of LoadRunner”);

                return 0;

}

lr_set_debug_message Example 2

We can see that this logging has been disabled in Runtime Setting, which we can see in in the screenshot given below

In the table given below. You can clearly see that the value for disabled log level is zero.

Log Level Value C Language Constants
Diabled 0 LR_MSG_CLASS_DISABLE_LOG

We can see above that log level of disabled logging is zero. Therefore we get the message in the output log that ” the current level is zero”. Output log is as given below. However, after execution of line number 5 which is printing the message as given below, logging has been disabled through code by use of this function which can be seen in line number 7 and after that no log is getting printed in the output log window of LoadRunner.

Loadrunner Output Window

Action.c(5): The current level is 0

Now we will run the same code for different runtime settings where logging has been enabled and Standard log has been selected which can be seen in the screenshot given below.

In the table given below, we can clearly see that the value of the log level Brief or Standard log is one.

Log Level Value C Language Constants
Brief 1 LR_MSG_CLASS_BRIEF_LOG

We know that Standard log is called as Brief and has value 1. Therefore we are getting the output as “The current level is 1” which can be seen in the output given below. We can also see that no log is getting printed after logging is disabled by use of this function lr_set_debug_message in the code itself.

Starting action Action.

Action.c(5): The current level is 1

Standard Log in Loadrunner

Let us execute the same code for different runtime setting where Extended log has been enabled as seen in the screenshot given below.

Logging in Loadrunner
Log Level Log Level Value C Language Constant
Extended Log 16 LR_MSG_CLASS_EXTENDED_LOG

We can see that Extended log has value 16. So we are getting log message in the output stating that The current level is 16. Main thing to be noted here is that after we are printing current log status in runtime setting and after that, we are disabling the log through the function lr_set_debug_message and after log has been disabled, we are not getting any output log. This is what the function lr_set_debug_message is for. This function is used for setting of LoadRunner Runtime Setting through script. We can see the output as given below.

Action.c(5): The current level is 16

We can see the output in the form of a screenshot given below.

Overall, we can say that it is a very useful function which is used to change the Runtime Setting of LoadRunner without going to Runtime Setting Window of LoadRunner function. We can do all type of runtime setting using this function. We have to use this function wisely to get productive results during preparation of performance testing script in LoadRunner.

For more read all our Loadrunner Functions

Leave a Comment