Home > Articles > Networking > Network Administration & Management

This chapter is from the book

This chapter is from the book

Logging Requests Conditionally

   SetEnvIf Request_URI "(\.gif|\.jpg)$" image

   CustomLog logs/access_log common env=!image


   SetEnvIf Remote_Addr 192\.168\.200\.5 specialma-

   chine

   CustomLog logs/special_access_log common env=spe-

   cialmachine

You can decide whether or not to log a request based on the presence of an environment variable. This variable can be previously set based on a number of parameters, such as the client's IP address or the presence of a certain header in the request. As shown in this example, the CustomLog directive can accept an environment variable as a third argument. If the environment variable is present, the entry will be logged; otherwise, it will not. If the environment variable is negated by prefixing it with an "!", the entry will be logged if the variable is not present. The example shows you how to avoid logging images in GIF and JPEG format and how to log requests from a particular IP address to a separate log file. See the next section for another example.

  • + Share This
  • 🔖 Save To Your Account