Forum Discussion

Larry_Wichter's avatar
Larry_Wichter
Icon for Nimbostratus rankNimbostratus
Jul 31, 2017

What are good or bad uses of irule Procs

I want to provide global debugging control over irules I have deployed so that I can target the logging of debug information for specific events, hosts, uri, vs, pool, etc, across these irules.

 

I plan to use a proc that will log a message to the LTM log if the current set of debug targets are met. The targets will be set as static variables.

 

This proc will be called multiple times in a variety of irules I have written to log debug information.

 

I am concerned that using a Proc will introduce a performance issue.

 

Please advise

 

1 Reply

  • Hi Larry,

     

    the execution of TCL procs does indeed introduce some overhead and personally I tend to avoid TCL procedures as much as possible.

     

    But especially for logging purposes they add so much flexibility while reducing the overall complexity of writing code that I'm still using them... 😉

     

    Below is the syntax I'm using for logging ...

     

    when RULE_INIT {
    
        set debug 9
    
        if { $debug >= 0 } then { call logger 0 "Emergency..." } 
        if { $debug >= 1 } then { call logger 1 "Alert..." }
        if { $debug >= 2 } then { call logger 2 "Critical..." } 
        if { $debug >= 3 } then { call logger 3 "Error..." } 
        if { $debug >= 4 } then { call logger 4 "Warning..." } 
        if { $debug >= 5 } then { call logger 5 "Notice..." } 
        if { $debug >= 6 } then { call logger 6 "Information..." } 
        if { $debug >= 7 } then { call logger 7 "Debug..." } 
        if { $debug >= 8 } then { call logger 8 "Strong Debug..." }
        if { $debug >= 9 } then { call logger 8 "Very Strong Debug..." }
    
    }
    
    proc logger { lvl msg } {
        switch -exact -- $lvl {
            0 {
                log -noname local0.emerg "$msg"
            }
            1 {
                log -noname local0.alert "$msg"
            }
            2 {
                log -noname local0.crit "$msg"
            }
            3 {
                log -noname local0.err "$msg"
            }
            4 {
                log -noname local0.warn "$msg"
            }
            5 {
                log -noname local0.notice "$msg"
            }
            6 {
                log -noname local0.info "$msg"
            }
            default {
                log -noname local0.debug "$msg"
            }
        }
    }
    

    Cheers, Kai