cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Debug Logging to your TrafficScript


#  Sub routines to allow for debug logging to easily be toggled on or off in a TrafficScript.


#  This routine will only trigger if connection.data.get("debug") returns "1"


#  Use the following  code in your TrafficScript to call it:




#      I usually let the user toggle debugging by putting something like


#      this in the top of the rule in a section marked "User editable section"


#######################################


#      User editable section:


$debug = 1;          # set to 0 to disable


#######################################




#      To set the rule up to enable debug logging, you need


#      to set the connection.data value for "debug" to "1"


#      I usually do this in a section of the rule marked "Don't edit past here"


#######################################


#       Don't edit past this line:


#######################################


if ( $debug = 1) {


  connection.data.set("debug", "1");


}




#sub routine to debug log at the "info" level


sub debuglog.info($message){


   if ( connection.data.get("debug") == "1") {


      log.info( "debuglog.info: __" . $message . "__ ");


   }


}



#sub routine to debug log at the "warn" level


sub debuglog.warn($message){


   if ( connection.data.get("debug") == "1") {


      log.warn( "debuglog.info: __" . $message . "__ ");


   }


}



#sub routine to debug log at the "error" level


sub debuglog.error($message){


   if ( connection.data.get("debug") == "1") {


      log.error( "debuglog.info: __" . $message . "__ ");


   }


}






#      When you want to log a debug line, all you need to do is call debuglog.info("This is my Message");


#      If debug is set to 1 in the rule, the line is logged, otherwise it will be ignored.



debuglog.info("If debugging is turned on, log this line of test to the event log with the severity level of: Info" );


debuglog.warn("If debugging is turned on, log this line of test to the event log with the severity level of: Warning" );


debuglog.error("If debugging is turned on, log this line of test to the event log with the severity level of: Error" );



















Version history
Revision #:
1 of 1
Last update:
‎01-22-2013 02:17:PM
Updated by: