You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Truesdell Douglas A <Tr...@JohnDeere.com> on 2014/10/13 20:11:27 UTC

[users@httpd] Make logging decision using two environment variables

I am trying to add replace the address field in a log when there is an X-Forwarded-For header following the notes in http://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html. This reference shows how to create and use the necessary condition on the CustomLog directive. But in my case the CustomLog directive has a pre-existing environment variable selecting for it. So I am now wanting to select the CustomLog based on two environment variables. The logic would say "Log using a given format if ${A} and ${B}".

The syntax for CustomLog supports a single "env" directive only. In addition, it appears that SetEnv can create a variable based only on a single property. Finally, "If" directives cannot use declared environment variables (since the If is evaluated before a declared variable is evaluated). So there seems to be no way to construct a logging decision in the form "A and B" using these tools. Is there some way to do this?

Re: [users@httpd] Make logging decision using two environment variables

Posted by Eric Covener <co...@gmail.com>.
On Mon, Oct 13, 2014 at 2:11 PM, Truesdell Douglas A <
TruesdellDouglasA@johndeere.com> wrote:

>  I am trying to add replace the address field in a log when there is an
> X-Forwarded-For header following the notes in
> http://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html.
> This reference shows how to create and use the necessary condition on the
> CustomLog directive. But in my case the CustomLog directive has a
> pre-existing environment variable selecting for it. So I am now wanting to
> select the CustomLog based on two environment variables. The logic would
> say “Log using a given format if ${A} and ${B}”.
>
>
>
> The syntax for CustomLog supports a single “env” directive only. In
> addition, it appears that SetEnv can create a variable based only on a
> single property. Finally, “If” directives cannot use declared environment
> variables (since the If is evaluated before a declared variable is
> evaluated). So there seems to be no way to construct a logging decision in
> the form “A and B” using these tools. Is there some way to do this?
>

​What sets your existing environment variable?​  If you currently use
SetEnv, you could move to SetEnvIf and have it set earlier. This would
allow you to use an expression in <if> that puts both variables in a string
and compares the concatenated value.



-- 
Eric Covener
covener@gmail.com