Conditional logging

Ezra Zygmuntowicz ezmobius at gmail.com
Thu Jul 19 22:47:00 MSD 2007


On Jul 19, 2007, at 10:20 AM, Paul Dlug wrote:

> Is there a way to log conditionally? For example, I have a load
> balancer checking a URL on nginx as a health check, there are a lot of
> them so I don't want them in my main log. Is there a way I can log
> conditionally based on IP or URL?
>
>
> Thanks,
> Paul
>


Paul-

	You can use the geo module to not log load balancer health checks  
like this:

   # include the load balancers we want omitted from the access log
   # http://wiki.codemongers.com/HWLoadbalancerCheckErrors
   geo $lb {
	  default      0;
     10.0.0.1/32  1;   # LB IPs
     10.0.0.3/32  1;
	}


# then inside of your server {} block use this error handler:

     error_page   400 /400;
     location = /400 {
         if ($lb) {
             access_log  off;
         }
         return 400;
     }


Cheers-

-- Ezra Zygmuntowicz 
-- Founder & Ruby Hacker
-- ez at engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)







More information about the nginx mailing list