Forum Discussion

Guillaume_Rouss's avatar
Guillaume_Rouss
Icon for Nimbostratus rankNimbostratus
Aug 12, 2019
Solved

Formating issue: default value for undefined variable

Hello. We're using an irule to log http access to a remote syslog server. I know there is also a dedicated profile for this, but we prefer to use a consistent implementation for all our logging ne...
  • Lee_Sutcliffe's avatar
    Aug 13, 2019

    You need to make sure you use the expr syntax when using a ternary operator within a variable.

    For example:

    % set colour [expr {"1" ? "red" : "blue"}]
    red
    % set colour [expr {"0" ? "red" : "blue"}]
    blue

    So looking at your example, you'd need to change it to be something like this.. (note that I have changed the from single to double quotation marks for the hyphen)

    set message  [format \
        "%s - %s \[%s\]..." \
        ... \
        [expr {[info exists [HTTP::username]] ? [HTTP::username] : "-" }]
    ]