Forum Discussion
irule static::debug
Hi everyone, I am bit confused, when i interpret irule shown below. Why should i use static::debug. Could you please explain the function of this.
when RULE_INIT {
set static::debug 0
}
when HTTP_REQUEST {
set cli [IP::remote_addr]:[TCP::remote_port]
set SessionId [HTTP::cookie ASP.NET_SessionId]
if {$static::debug}{log local0. "Client: $cli Request SessionId: >$SessionId<"}
if { $SessionId != "" } { persist uie $SessionId 3000 }
}
}
3 Replies
- Kevin_Stewart
Employee
It's a static variable, similar to static (global) variables you'd use in other programming languages. So you're setting it once and reading it throughout the code. In this case it's being used to globally enable (1) or disable (0) logging in the iRule.
- Kevin_Stewart
Employee
in this line what can be the value of static debug 0 or 1 can it be changed ?
You're using a 1 for "true" and 0 for "false", but you could use any logical true/false equivalent values here.
The iRule has it set to 0 (false), so to enable logging just change the 0 to 1 (true).
- VernonWells
Employee
A few things to note:
-
It is global [1], so while it is common to see
, it's not best-practice to do so. The reason is, if you usestatic::debug
in more than one iRule, and set it to different values in each of the rules, the final value will apply to all iRules and will be essentially non-deterministic [2]. There are several ways to remedy this, but a common approach -- and the one I think is easiest -- is to simply choose a unique prefix for each iRule. So, if you have three rules that want to usestatic::debug
, you might usestatic::debug
,static::abc_debug
andstatic::def_debug
(okay, use something more meaningful thatstatic::ghi_debug
, etc.);abc_ -
These
commands will be evaluated on each connection. So, while the use of the "debug" value is useful when building or changing an iRule, I strongly recommend commenting these out (or removing them) for production. For complex rules, some people create an iApp which essentially inserts debugging into a rule (or uncomments existing statements) so that debugging can be "turned on" and "turned off".if { $static::abc_debug } { ... }
[1] To be completely pedantic, it is tied to a tmm, so if you were to change this or any
scoped variable, the change would be visible only to other connections being processed on the tmm instance where the change was made. There is a valid and quite useful case for this, but 99% of the time -- and unless you really know what you're doing and why -- treat astatic::
variable as a constant and don't change it.static::[2] It will be the value in the last iRule loaded which attempts to set this value, but that ordering could change over time.
-
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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