Using uninitialized "pat" variable while logging request

Hi,

to debug my locations, I have a variable in my configuration that I
reference during logging. The log format, included from nginx.conf:

log_format mylogformat '$remote_addr - $remote_user [$time_local]
$request ’
'“$status” $body_bytes_sent “$http_referer” ’
‘“$http_user_agent” domain: $host branch: $pat’;

Unfortunately, I cannot set the variable $pat already in nginx.conf,
but in my virtual server configuration, I set it like this:

server {
    listen          1.2.3.4:80 default_server;
    server_name     www.example.com;

charset utf-8;
set $pat “-”;

    # rest of configuration here, eg.:

location = / {
set $pat “homepage”;
# do something special
}

    # more stuff...
}

So far, my understanding is that the variable $pat should be always
defined, right? Well… I find this in the error log:

[warn] 11092#0: *15719589 using uninitialized “pat” variable while
logging request, client: 4.3.2.1, server: www.example.com

For a lot of requests, the value of the variable does appear in the log
file, but for a good proportion, it doesn’t. I would like to have this
variable always set properly. Can it be a timing question? I get
between ~5 and below 100 requests per second. The machine doesn’t look
anywhere near loaded, though (CPU utulization is under 5%).

My software is nginx-full 1.2.1-2.2+wheezy1, on an amd64 VM.

TIA!

Kind regards,
–Toni++

On Saturday 16 November 2013 02:24:43 Toni M. wrote:

Unfortunately, I cannot set the variable $pat already in nginx.conf,

defined, right? Well… I find this in the error log:
[…]

The “set” directive isn’t something essential, and actually it is just a
directive from the rewrite module.

See here how it works:
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

It is evaluated on the rewrite phase of request processing. Thus, if
the request is finalized before this phase, then your variable is left
uninitialized.

To debug your locations and for better understanding what is going on,
you can use nginx debug log: A debugging log

wbr, Valentin V. Bartenev

Hi,

On Sat, Nov 16, 2013 at 04:07:19AM +0400, Valentin V. Bartenev wrote:

The “set” directive isn’t something essential, and actually it is just a
directive from the rewrite module.

See here how it works:
Module ngx_http_rewrite_module
It is evaluated on the rewrite phase of request processing. Thus, if
the request is finalized before this phase, then your variable is left
uninitialized.

Thanks for the explanation - I did not get that from this page. :confused:

To debug your locations and for better understanding what is going on,
you can use nginx debug log: A debugging log

Unfortunately, there is nothing between the info (too little) and
debug log levels (too much). But it was fruitful, as I found the
problem. :slight_smile:

Cheers,
–Toni++

On 16 Nov 2013 01:02, “Toni M.” [email protected] wrote:

Unfortunately, there is nothing between the info (too little) and
debug log levels (too much). But it was fruitful, as I found the
problem. :slight_smile:

Why don’t you let the list know how you fixed it, so the next person
with
the same problem can find the answer in the list archives?