Debugging Rules
The TrafficScript function log.info() can be used to log a message to the error log (ZEUSHOME/log/errors).
Consider the following code:
if( string.contains( http.getPath(), "root.exe" ) ) {
log.info( "Discarding potential nimda attack" );
connection.discard();
}This appends the following message to your error log file:
$ export ZEUSHOME=/usr/local/zeus
$ tail $ZEUSHOME/log/errors
[20/Dec/2014:10:24:46 +0000] INFO rules/RuleName rulelogmsginfo vservers/VSname Discarding potential nimda attack
You can also inspect your error log file by clicking Event Log in the Traffic Manager Admin UI.
When you are debugging a rule, use log.info() to print out progress messages as the rule executes. log.info() requires a string parameter; you can construct complex strings by appending variables and literals together using the “.” operator:
$msg = "Received ".connection.getDataLen()." bytes.";
log.info( $msg );The functions log.warn() and log.error() are similar to log.info(). They prefix error log messages with a higher priority - either “WARN” or “ERROR”. Use the Event Log viewer to filter out low-priority messages.
Be careful when printing out connection data verbatim as the connection data might contain control characters or other non-printable characters. You can encode data using either “string.hexEncode()” or “string.escape()”.
You should use “string.hexEncode()” if the data is binary, and “string.escape()” if the data contains readable text with a small amount of non-printable characters.
