Y-lib
Loadrunner libraries
|
Logging-related y-lib functions. More...
Go to the source code of this file.
Functions | |
char * | y_make_datetimestamp (time_t time, unsigned short millitm) |
Convert a unixtime style timestamp to a date and time represented as YYYY-MM-DD HH:MM:SS.mmm. More... | |
char * | y_get_datetimestamp () |
Returns the current time converted represented as YYYY-MM-DD HH:MM:SS.mmm. More... | |
void | y_setup_logging () |
Turn on 'extra logging', when available. More... | |
void | y_log_to_report (char *message) |
If extra logging was enabled force a line to be logged to the logfile - even if regular logging was turned off. Enable extra logging by calling y_setup_logging() More... | |
void | y_log_error (char *message) |
Log an error message, with a timestamp, if extra logging is enabled. More... | |
void | y_log_warning (char *message) |
Log a warning, with a timestamp, if extra logging is enabled. More... | |
void | y_log_save () |
Save the loglevel for later restoration through y_log_restore(). More... | |
void | y_log_turn_off_without_saving () |
Force all logging off unconditionally, without saving the old state. More... | |
void | y_log_turn_off () |
Save the current loglevel and turn off logging. More... | |
void | y_log_turn_off_permanently () |
Turn all logging off and make sure it stays that way. More... | |
void | y_log_set_brief () |
Set the log level to "brief" messages only. More... | |
void | y_log_set_extended () |
Set the log level to show all messages, including extended result data, parameters, and tracing information. More... | |
void | y_log_restore () |
Restore the loglevel to previous state. To be exact, it will restore it to the state it was in before the last call to y_log_set_{off|on|brief|extended}() or y_log_save(). More... | |
void | y_log_turn_on () |
Turn logging on. More... | |
void | y_log_force_message (char *message) |
Log a message forcefully, bypassing the current log settings. More... | |
int | y_write_to_log (char *filename, char *content) |
Write a string prepended with date and time to the specified (log)file. More... | |
void | y_disk_space_guard (double max_free_percentage) |
Detect low disk space situations on the generator and turn all logging off if not enough space is left. More... | |
void | y_disk_space_usage_guard (double limit_mebibytes_used) |
Detect excessive disk usage by the test and turn all further logging off if more than a specific limit number of mebibytes has been used. More... | |
Logging-related y-lib functions.
Note that some of these are a bit marginal - the disk space guards for instance are logging related in the sense that they will turn all logging off when too much disk space has been used, but they aren't exactly log manipulation functions in the low-level sense.
Definition in file y_logging.c.
void y_disk_space_guard | ( | double | max_free_percentage | ) |
Detect low disk space situations on the generator and turn all logging off if not enough space is left.
When called, this function will check the amount of space left on the generator's "output" device / directory. If the percentage of free space is lower than the treshold percentage, it will generate an error transaction "---DISK SPACE LOW IN LOG FOLDER FOR {y_hostname_generator}---" and turn all further logging off until the end of the test, using y_log_turn_off_permanently().
Loadrunner does not protect the generators' disks from overflowing, even if the test is writing out a lot of information to the logs really quickly. If a disk fills up on the generator or the disk the controller uses for results collation overflows there is no graceful recovery. Collation will fail and test results may be hard or impossible to recover. This kind of situation can occur when temporary service disruptions happen (triggering a flood of 'log on error' messages), but also if runtime settings are incorrect and the test was configured to log everything.
In order to prevent this from happening scripts should regularly call to both y_disk_space_guard() and y_disk_space_usage_guard() with some reasonable limits.
[in] | max_free_percentage | The amount of free diskspace as a percentage of total space that will cause the logging to turn off. |
Definition at line 401 of file y_logging.c.
void y_disk_space_usage_guard | ( | double | limit_mebibytes_used | ) |
Detect excessive disk usage by the test and turn all further logging off if more than a specific limit number of mebibytes has been used.
When called, this function will check the amount of space used on the generator's "output" device / directory since the first call to this function. If the amount of used space exceeds the treshold it will generate an error transaction "---DISK SPACE LOW IN LOG FOLDER FOR {y_hostname_generator}---" and turn all further logging off until the end of the test, using y_log_turn_off_permanently().
Loadrunner does not protect the generators' disks from overflowing, even if the test is writing out a lot of information to the logs really quickly. If a disk fills up on the generator or the disk the controller uses for results collation overflows there is no graceful recovery. Collation will fail and test results may be hard or impossible to recover. This kind of situation can occur when temporary service disruptions happen (triggering a flood of 'log on error' messages), but also if runtime settings are incorrect and the test was configured to log everything.
In order to prevent this from happening scripts should regularly call to both y_disk_space_guard() and y_disk_space_usage_guard() with some reasonable limits.
[in] | limit_mebibytes_used | The amount of mebibytes the test is allowed to used on the generator's target directory. |
Definition at line 456 of file y_logging.c.
char* y_get_datetimestamp | ( | ) |
Returns the current time converted represented as YYYY-MM-DD HH:MM:SS.mmm.
Definition at line 87 of file y_logging.c.
void y_log_error | ( | char * | message | ) |
Log an error message, with a timestamp, if extra logging is enabled.
[in] | message | The error message to be logged. |
Definition at line 153 of file y_logging.c.
void y_log_force_message | ( | char * | message | ) |
Log a message forcefully, bypassing the current log settings.
Typically used for generating datafiles within scripts with the loglevel set to OFF, or things of that sort.
Example:
Definition at line 328 of file y_logging.c.
void y_log_restore | ( | ) |
Restore the loglevel to previous state. To be exact, it will restore it to the state it was in before the last call to y_log_set_{off|on|brief|extended}() or y_log_save().
Definition at line 274 of file y_logging.c.
void y_log_save | ( | ) |
Save the loglevel for later restoration through y_log_restore().
This is called by the various y_log_* functions to make sure the loglevel can be put back the way it was.
Definition at line 182 of file y_logging.c.
void y_log_set_brief | ( | ) |
Set the log level to "brief" messages only.
Useful when you want to, say, not see that big PDF you are downloading somewhere in your logs but do want to see the rest of the logging.
Definition at line 241 of file y_logging.c.
void y_log_set_extended | ( | ) |
Set the log level to show all messages, including extended result data, parameters, and tracing information.
Useful when you want to debug a particular step in the script.
Definition at line 256 of file y_logging.c.
void y_log_to_report | ( | char * | message | ) |
If extra logging was enabled force a line to be logged to the logfile - even if regular logging was turned off. Enable extra logging by calling y_setup_logging()
[in] | message | The message to be logged. |
Definition at line 128 of file y_logging.c.
void y_log_turn_off | ( | ) |
Save the current loglevel and turn off logging.
Definition at line 213 of file y_logging.c.
void y_log_turn_off_permanently | ( | ) |
Turn all logging off and make sure it stays that way.
This will overwrite the state saved by y_log_save() with "No logging at all, please.", so that y_log_restore() can't turn things back on.
Definition at line 228 of file y_logging.c.
void y_log_turn_off_without_saving | ( | ) |
Force all logging off unconditionally, without saving the old state.
This is used by various y_log_* functions to get the loglevel to a known state.
Definition at line 195 of file y_logging.c.
void y_log_turn_on | ( | ) |
Turn logging on.
What this function does depends on the saved loglevel.
Definition at line 302 of file y_logging.c.
void y_log_warning | ( | char * | message | ) |
Log a warning, with a timestamp, if extra logging is enabled.
[in] | message | The error message to be logged. |
Definition at line 167 of file y_logging.c.
char* y_make_datetimestamp | ( | time_t | time, |
unsigned short | millitm | ||
) |
Convert a unixtime style timestamp to a date and time represented as YYYY-MM-DD HH:MM:SS.mmm.
[in] | time | - the unix time stamp, as reported by ftime() |
millitm | - the milliseconds belonging to the time stamp |
Definition at line 60 of file y_logging.c.
void y_setup_logging | ( | ) |
Turn on 'extra logging', when available.
This is one of the remnants of a bit of old code that would log every transaction stop/start with a timestamp, so that post-test-analysis of responstimes could be done with custom tools. Unless you are running a very old y-lib based script there is no reason why you should use this, as y_set_start_transaction_impl() and y_set_end_transaction_impl() should give you the tools you need to do something like that without polluting y-lib with it ;-)
Definition at line 110 of file y_logging.c.
int y_write_to_log | ( | char * | filename, |
char * | content | ||
) |
Write a string prepended with date and time to the specified (log)file.
The logged line will have the following format: YYYYMM,DDHHmmss,{y_virtual_user_group},{y_virtual_user_id},{y_scid},{content}
[in] | filename | The file name of the target file. |
[in] | content | The logmessage to be written. |
Example:
Example output: 20091126,215212,SomeGroup,3,4,Everything went great
Definition at line 354 of file y_logging.c.