So a I am adding in default values - i presume they are called at the time
it fails with
<CLIENT_ACCEPTED> - proc loggingNowStr not found (line 44) invoked from within "call loggingNowStr $log_cca_clock $log_cca_msec "
<CLIENT_ACCEPTED> - proc loggingNowStr not found (line 44) invoked from within "call loggingNowStr “$log_cca_clock” “$log_cca_msec” "
HI @AlexS_yb , it looks like it doesn’t like clock to provide default values there…got the same errors you did until I just tried a test pattern. RULE_INIT works just fine for me otherwise.
rule proc_lib {
proc loggingNowStr { {log_now_clock 123456789} {log_now_msec 78341239432} } {
set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }]
incr log_now_clock [ expr { $log_now_diff / 1000 }]
set log_now_fract [expr { $log_now_diff % 1000 }]
set log_now_fract [format "%03d" $log_now_fract]
set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"]
return $log_now_start_time_str
}
}
rule init_proc_test {
when RULE_INIT {
set x [call proc_lib::loggingNowStr]
set y [call proc_lib::loggingNowStr [clock clicks] [clock clicks -milliseconds]]
log local0. "Default args: $x; Provided args: $y"
}
}
### RESULT ###
Jul 28 00:06:29 ltm3.test.local info tmm1[20054]: Rule /Common/init_proc_test : Default args: 1972-06-25 12:27:19.432; Provided args: 2022-07-28 00:06:29.879
I centralize all my procedures together in a library iRule that I call proc_lib so they can be maintained / managed separately from the logic of individual iRules. I updated my example to show the two named iRule objects, proc_lib and init_proc_test. First I created your procedure (unchanged except for a static default value for each argument) in the proc_lib iRule and then I added the init_proc_test iRule, which generated the resulting log entry when I saved it due to the RULE_INIT event firing and calling that loggingNowStr procedure in the proc_lib iRule twice, the first time with defaults in use and the second time with clock command values sent as arguments.
I’ve never seen the setting of procedure default values to be the output of a command. Probably better to code it so that you set default to be false and then check whether it is still false. If not, set it to the output of the command:
proc loggingNowStr { {log_now_clock 0} {log_now_msec 0} } {
if { $log_now_clock == 0 } {
set log_now_clock [clock seconds]
}
if { $log_now_msec == 0 } {
set log_now_msec [clock clicks -milliseconds]
}
set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }]
incr log_now_clock [ expr { $log_now_diff / 1000 }]
set log_now_fract [expr { $log_now_diff % 1000 }]
set log_now_fract [format "%03d" $log_now_fract]
set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"]
return $log_now_start_time_str
}
@AlexS_yb - If your post was solved it would be helpful to the community if you selected *Accept As Solution* on the relevant reply (or replies). This helps future readers find answers more quickly and confirms the efforts of those who helped. Thanks for being part of our community.