Friday, October 4, 2013

Printing the current log options to the output log (even if logging is disabled) in load runner

// Prints the current log options to the output log (even if logging is disabled)
// Example: xyz_print_log_options(lr_get_debug_message());
void xyz_print_log_options(unsigned int log_options_to_print) {
 char buf[(4 * 8) + 1]; // sizeof(unsigned int) is always 4 bytes in LoadRunner.
 unsigned int original_log_options = lr_get_debug_message();
 
 xyz_clear_log_options();
 xyz_set_log_options(LR_MSG_CLASS_BRIEF_LOG);
 
 // Print the bit pattern for the current log options.
 itoa(log_options_to_print, buf, 2);
 lr_output_message("Log options bit pattern: %032.32s", buf);
 
 lr_output_message("Log options selected:");
 
 if (log_options_to_print == 0) {
  lr_output_message("* Disabled (LR_MSG_CLASS_DISABLE_LOG)");
 } else {
 
  if (log_options_to_print & LR_MSG_CLASS_JIT_LOG_ON_ERROR) {
   lr_output_message("* Send messages only when an error occurs (LR_MSG_CLASS_JIT_LOG_ON_ERROR)");
  } else {
   lr_output_message("* Always send messages");
  }
 
  if (log_options_to_print & LR_MSG_CLASS_BRIEF_LOG) {
   lr_output_message("* Log messages at the detail level of \"Standard log\" (LR_MSG_CLASS_BRIEF_LOG)");
  }
 
  if (log_options_to_print & LR_MSG_CLASS_EXTENDED_LOG) {
   lr_output_message("* Log messages at the detail level of \"Extended log\" (LR_MSG_CLASS_EXTENDED_LOG)");
  }
 
  if (log_options_to_print & LR_MSG_CLASS_PARAMETERS) {
   lr_output_message("* Parameter substitution (LR_MSG_CLASS_PARAMETERS)");
  }
 
  if (log_options_to_print & LR_MSG_CLASS_RESULT_DATA) {
   lr_output_message("* Data returned by server (LR_MSG_CLASS_RESULT_DATA)");
  }
 
  if (log_options_to_print & LR_MSG_CLASS_FULL_TRACE) {
   lr_output_message("* Advanced trace (LR_MSG_CLASS_FULL_TRACE)");
  }
 }
 
 xyz_clear_log_options();
 xyz_set_log_options(original_log_options);
 
 return;
}
/*
Output looks like this:
globals.h(26): Log options bit pattern: 00000000000000000000001000011110
globals.h(28): Log options selected:
globals.h(35): * Send messages only when an error occurs (LR_MSG_CLASS_JIT_LOG_ON_ERROR)
globals.h(45): * Log messages at the detail level of "Extended log" (LR_MSG_CLASS_EXTENDED_LOG)
globals.h(49): * Parameter substitution (LR_MSG_CLASS_PARAMETERS)
globals.h(53): * Data returned by server (LR_MSG_CLASS_RESULT_DATA)
globals.h(57): * Advanced trace (LR_MSG_CLASS_FULL_TRACE)
*/

No comments: