Forum Discussion

Algebraic_Mirror's avatar
Algebraic_Mirror
Icon for Cirrostratus rankCirrostratus
Jan 30, 2018

Proper way to do debugging in an iRule

What is the best way to place extra logging statements in an iRule for potential future debugging? If I have a statement like this, will it not print to the log until someone turns debug level logging on for iRules system wide (eg - System -> Logs -> Configuration -> Options, and then under the local traffic manager section, change the iRules dropdown to debug)?

log local0.debug "Here is a log statement."

Or, do I first need to check some system variable to see if iRules have been set to debug level, and only then run that log statement?

Basically, my goal is to have nice debugging in my iRules that turns on when people set logging on the system to debug, and off otherwise.

1 Reply

  • One of the more common (and simplest) methods is to set a variable, if enabled it will log the messages to /var/log/ltm. To turn it on you just need to set the variable to 1, set to 0 to disable. Using a global static variable means you can use it in multiple iRules so you only need to enable/disable it in one place

     

    when RULE_INIT {
      set 1 to enable logging, 0 to disable
      set static::debug 1
    }
    
    when HTTP_REQUEST {
    
      some code....
    
      if {$static::debug}{log local0. "logging is enabled"}  
    }