You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Apisilp Trunganont <ap...@hotmail.com> on 2002/09/21 23:43:16 UTC

[users@httpd] How to use logical operators in conditional log?

Hello,

I'm using this config to log my web access.

SetEnvIf Request_URI "^/test1/" test1_log test1_test2_log
SetEnvIf Request_URI "^/test2/" test2_log test1_test2_log
CustomLog /log/access_log1 combined env=test1_log
CustomLog /log/access_log2 combined env=test2_log
CustomLog /log/access_log combined env=test1_test2_log

This gives every requests on /test1/ is logged to access_log1,
every requests on /test2/ is logged to access_log2 and every
requests on other directories is logged to access_log.

But I want to use more complex condition to reduce my
log file size and reduce the time for log analyze. I've
decided new conditional log like this.

*.gif and *.jpg on /test1/ must be logged to access_log1_img
other extensions on /test1/ must be logged to access_log1
*.gif and *.jpg on /test2/ must be logged to access_log2_img
other extensions on /test2/ must be logged to access_log2
*.gif and *.jpg on other directories must be logged to access_log_img
other extensions on other directories must be logged to access_log

So I've tried to use this config.

SetEnvIf Request_URI "^/test1/" test1_log test1_test2_log
SetEnvIf Request_URI "^/test2/" test2_log test1_test2_log
SetEnvIf Request_URI "\.(gif|jpg)$" img_log
CustomLog /log/access_log1 combined env=(test1_log&!img_log)
CustomLog /log/access_log1_img combined env=(test1_log&img_log)
CustomLog /log/access_log2 combined env=(test2_log&!img_log)
CustomLog /log/access_log2_img combined env=(test2_log&img_log)
CustomLog /log/access_log combined env=(test1_test2_log&!img_log)
CustomLog /log/access_log_img combined env=(test1_test2_log&img_log)

But it doesn't work. :-( So I've tried to use more complex regexp
like this.

SetEnvIf Request_URI "^/test1/(.*?)(?<!\.(gif|jpg))$" test1_no_img_log
SetEnvIf Request_URI "^/test1/.*\.(gif|jpg)$" test1_img_log
CustomLog /log/access_log1 combined env=test1_no_img_log
CustomLog /log/access_log1_img combined env=test1_img_log

It doesn't work again. Apache doesn't support complex regexp. :-(

Anyone knows how to use logical operators (and/or) in CustomLog?
Or is there another method to implement this?

Thanks,
Apisilp.


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to use logical operators in conditional log?

Posted by Joshua Slive <jo...@slive.ca>.
Apisilp Trunganont wrote:

> 
> *.gif and *.jpg on /test1/ must be logged to access_log1_img
> other extensions on /test1/ must be logged to access_log1
> *.gif and *.jpg on /test2/ must be logged to access_log2_img
> other extensions on /test2/ must be logged to access_log2
> *.gif and *.jpg on other directories must be logged to access_log_img
> other extensions on other directories must be logged to access_log

In general, this is a bad idea; just use a decent log post-processor to 
get what you want.

But if you insist, here's something to get you started.  I'm sure it is 
not the best way to do it, but it should work.  (I only dealt with 
/test1/.  It should be obvious how to add test2.)

SetEnvIf Request_URI ".*" img=0
SetEnvIf Request_URI "^/test1/" test1=1
SetEnvIf Request_URI "\.(gif|jpg)$" img=1

SetEnvIf test1 1 access_log1
SetEnvIf img 1 !access_log1
CustomLog /log/access_log1 combined env=access_log1

SetEnvIf test1 1 access_log1_img
SetEnvIf img 0 !access_log1_img
CustomLog /log/access_log1 combined env=access_log1

SetEnvIf Request_URI .* access_log_img
SetEnvIf img 0 !access_log_img
SetEnvIf test1 !access_log_img
CustomLog /log/access_log_img combined env=access_log_img

SetEnvIf Request_URI .* access_log
SetEnvIf test1 1 !access_log
SetEnvIf img 1 !access_log
CustomLog /log/access_log combined env=access_log

Joshua.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org