Forum Discussion
krisdames
Cirrus
Apr 19, 2013Conditional logging
Hi,
I typically put this at the top of all my irules (learned it from the F5 consultant that set up our BigIP). This allows me to easily turn debugging on and off:
if { $static::debug } { log local0. "debugging message" }
I'd like to create a block of logging statements like so (Example B):
if { $static::debug } {
log local0. "debugging message 1"
log local0. "debugging message 2"
}
But this does not seem to work. Both debug messages get logged, regardless of the value of static::debug. What am I doing wrong?
--
Kris
6 Replies
- Kevin_Stewart
Employee
The static namespace is global to the BOX, so if you're using the static::debug variable in all of your iRules, it'll take the value (globally) of the last updated iRule. - krisdames
Cirrus
Oh...well that makes perfect sense then. I also just found this which explains that: https://devcentral.f5.com/wiki/iRules.static.ashx
Thanks for the timely reply. Time to change my iRules! :)
--
Kris - krisdames
Cirrus
I also just learned this interesting tidbit:
The only time this becomes even slightly confusing is when setting variables in the RULE_INIT event. All variables set under this event are treated as global, so keep that in mind. The same commands may be used against either local or global variables, though, so keep an eye out.
Source: https://devcentral.f5.com/tech-tips/articles/irules-101-03-variables
So not only should I not use the static namespace but I need a unique variable name if I want to initialize it in the RULE_INIT event, because even if I try to use a local variable it will actually be a global variable!
--
Kris - Kevin_Stewart
Employee
True statement about RULE_INIT variables. The biggest difference is how the variables are stored and accessed. The static namespace is specifically designed for CMP-compatibility - meaning the variables will be accessible across TMM instances. A non-static global variable is not only not CMP-capable, but will likely demote the entire virtual server to a single TMM (not good for performance). So static global variables can be a good thing, if used properly.
By the way, while they are intended to be read-only once set, you can change a static global variable outside of RULE_INIT, but doing so will break CMP for that variable. - Colin_Walker_12Historic F5 AccountKevin is, as usual, spot on about how RULE_INIT works and how to deal with variables being named and set there. There are also some mutterings internally about possibly looking at how this works and changing it in future versions. If you've got feedback on how this would work for you, now is definitely the time to let us know...don't be shy. ;)
Thoughts?
Colin - nitass
Employee
Kris, just in case if you have not yet seen this article. it is pretty handy.
iRules logging to multiple locations with ease by Dan Holland
https://devcentral.f5.com/tech-tips/articles/irules-logging-to-multiple-locations-with-ease
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects