You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tofu Optimist <to...@yahoo.com> on 2003/09/02 22:02:16 UTC

Custom Log files Under MP2

I would like to append a small line of log information
to a file on certain apache2 requests.  For this
application, I am very concerned about speed, so i'm
looking for fast simple solutions. 

I could stuff the information in the error log as per
http://perl.apache.org/docs/2.0/api/Apache/Log.html, 
and parse it out later off-line, but I'd prefer to
reserve the error log for errors.

I could stuff the information in the access log, and
likewise pull out the data later off-line: how might I
get data to the access_log?

The most natural place to append the information would
be a dedicated file.  I've never written to a file
from mod_perl, and don't know the correct idiom
(flock? etc?) to do so.  

I'd appreciate any pointers to recipes, modules, etc.
to show me the correct (fast, reliable) way to append
to a file under MP2.

Thanks!

:)

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Custom Log files Under MP2

Posted by Stas Bekman <st...@stason.org>.
Tofu Optimist wrote:
> I would like to append a small line of log information
> to a file on certain apache2 requests.  For this
> application, I am very concerned about speed, so i'm
> looking for fast simple solutions. 
> 
> I could stuff the information in the error log as per
> http://perl.apache.org/docs/2.0/api/Apache/Log.html, 
> and parse it out later off-line, but I'd prefer to
> reserve the error log for errors.
> 
> I could stuff the information in the access log, and
> likewise pull out the data later off-line: how might I
> get data to the access_log?
> 
> The most natural place to append the information would
> be a dedicated file.  I've never written to a file
> from mod_perl, and don't know the correct idiom
> (flock? etc?) to do so.  
> 
> I'd appreciate any pointers to recipes, modules, etc.
> to show me the correct (fast, reliable) way to append
> to a file under MP2.

You may want to spend some time with the mp2 docs first.
http://perl.apache.org/docs/2.0/user/

Your particular question is answered at these locations:
http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlLogHandler
http://perl.apache.org/docs/2.0/user/handlers/server.html#Startup_Phases_Demonstration_Module

As for flocking, I prefer to do that, even though there are claims that short 
writes are atomic. It's probably not the same on all io implementations.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Custom Log files Under MP2

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Tofu Optimist wrote:
> Specifically,
> I'd like to log certain image file requests (all files
> with .jpg, .gif, and .png extensions) to a custom log,
> 
> image_log, logging IP, file, time, status, bytes,
> referer, cookies, etc. 
> 
> I care about speed here.
> 
> Would you suggest a native logging 
>  http://www.modperlcookbook.org/chapters/ch16.pdf 
> 
> or take this route
> http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlLogHandler

native Apache routines, written in C, will always be faster, so if you can 
get the same functionality from native routines use them.  it's the 
flexibility mod_perl offers that makes it special :)

> 
> If the former, would you have any sample 
> config code to illustrate?

I think the conditional logging recipe is pretty descriptive.  see also the 
CustomLog directive description in the apache documentation

http://httpd.apache.org/docs-2.0/mod/directives.html

FilesMatch might also help.

--Geoff

> 
> Thanks!
> 
> -TO
> 
> 
> 
> 
> 
> --- Geoffrey Young <ge...@modperlcookbook.org> wrote:
> 
>>
>>Tofu Optimist wrote:
>>
>>>I would like to append a small line of log
>>
>>information
>>
>>>to a file on certain apache2 requests.  For this
>>>application, I am very concerned about speed, so
>>
>>i'm
>>
>>>looking for fast simple solutions. 
>>
>>if speed is the concern, just stick to apache's
>>native logging mechanism.
>>
>>see recipe 16.5, "Conditional Logging" in the
>>mod_perl developer's cookbook:
>>
>>http://www.modperlcookbook.org/chapters/ch16.pdf
>>
>>in mod_perl 2.0, it's still $r->subprocess_env(),
>>but you need to load 
>>APR::Table first.
>>
>>HTH
>>
>>--Geoff
>>
>>
>>
>>-- 
>>Reporting bugs: http://perl.apache.org/bugs/
>>Mail list info:
>>http://perl.apache.org/maillist/modperl.html
>>
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com


Re: Custom Log files Under MP2

Posted by Tofu Optimist <to...@yahoo.com>.
Specifically,
I'd like to log certain image file requests (all files
with .jpg, .gif, and .png extensions) to a custom log,

image_log, logging IP, file, time, status, bytes,
referer, cookies, etc. 

I care about speed here.

Would you suggest a native logging 
 http://www.modperlcookbook.org/chapters/ch16.pdf 

or take this route
http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlLogHandler

If the former, would you have any sample 
config code to illustrate?

Thanks!

-TO





--- Geoffrey Young <ge...@modperlcookbook.org> wrote:
> 
> 
> Tofu Optimist wrote:
> > I would like to append a small line of log
> information
> > to a file on certain apache2 requests.  For this
> > application, I am very concerned about speed, so
> i'm
> > looking for fast simple solutions. 
> 
> if speed is the concern, just stick to apache's
> native logging mechanism.
> 
> see recipe 16.5, "Conditional Logging" in the
> mod_perl developer's cookbook:
> 
> http://www.modperlcookbook.org/chapters/ch16.pdf
> 
> in mod_perl 2.0, it's still $r->subprocess_env(),
> but you need to load 
> APR::Table first.
> 
> HTH
> 
> --Geoff
> 
> 
> 
> -- 
> Reporting bugs: http://perl.apache.org/bugs/
> Mail list info:
> http://perl.apache.org/maillist/modperl.html
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Custom Log files Under MP2

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Tofu Optimist wrote:
> I would like to append a small line of log information
> to a file on certain apache2 requests.  For this
> application, I am very concerned about speed, so i'm
> looking for fast simple solutions. 

if speed is the concern, just stick to apache's native logging mechanism.

see recipe 16.5, "Conditional Logging" in the mod_perl developer's cookbook:

http://www.modperlcookbook.org/chapters/ch16.pdf

in mod_perl 2.0, it's still $r->subprocess_env(), but you need to load 
APR::Table first.

HTH

--Geoff



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html