Forum Discussion
Guillaume_Rouss
Nimbostratus
Aug 12, 2019Formating 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...
- 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] : "-" }] ]
Lee_Sutcliffe
Nacreous
Aug 13, 2019You 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] : "-" }]
]
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