You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by oh...@cox.net on 2012/07/01 18:43:20 UTC

"Best practices" or recommendations for logging from a module?

Hi,

I'm working on my 1st module, and everything seems to be working so far.  At this point, since it's a first module, and I've been doing lots of debugging, mostly running Apache in single process mode (-k start -X), I've only been using printf to output various things.

I am somewhat loath to remove some of the printf output, esp. since my module is still pretty raw (though working), but I'm starting to look into how I can switch from using printf to whatever is "normally" used for logging output from Apache modules.

Given that I don't want to completely remove the ability to output the debug output, is there a best practice for logging from an Apache module?  Is it just to use the apr logging calls, and set the level to debug?

Thanks,
Jim





Re: "Best practices" or recommendations for logging from a module?

Posted by Joe Lewis <jo...@joe-lewis.com>.
On 07/01/2012 05:28 PM, ohaya@cox.net wrote:
> ---- Joe Lewis<jo...@joe-lewis.com>  wrote:
>    
>> On 07/01/2012 01:53 PM, ohaya@cox.net wrote:
>>      
>>> ---- Joe Lewis<jo...@joe-lewis.com>   wrote:
>>>
>>>        
>>>> On 07/01/2012 12:55 PM, ohaya@cox.net wrote:
>>>>
>>>>          
>>>>> ---- ohaya@cox.net wrote:
>>>>>
>>>>>
>>>>>            
>>>>>> ---- ohaya@cox.net wrote:
>>>>>>
>>>>>>
>>>>>>              
>>>>>>> ---- Joe Lewis<jl...@silverhawk.net>    wrote:
>>>>>>>
>>>>>>>
>>>>>>>                
>>>>>>>> Jim, you could use the log_error funtion all the time. Log_perror javits
>>>>>>>> logging associated with a pool, and log_rerror is for requests. If
>>>>>>>> possible, use log_rerror, because it puts the up address, etc into the logs.
>>>>>>>>
>>>>>>>> Joe
>>>>>>>> On Jul 1, 2012 10:56 AM,<oh...@cox.net>    wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>                  
>>>>>>> Joe,
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> Jim
>>>>>>>
>>>>>>>
>>>>>>>                
>>>>>> Hi,
>>>>>>
>>>>>> Oh, oh :(.
>>>>>>
>>>>>> I'm using:
>>>>>>
>>>>>> ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,<my message>);
>>>>>>
>>>>>> all over the place, and even though I have only one LogLevel in the httpd;conf, at the top level, set to "debug", I don't see those messages.
>>>>>>
>>>>>> The only ones I see are the ones that use APLOG_NOTICE.
>>>>>>
>>>>>> Why is this?  I thought that with LogLevel set to debug, that I should see all level msgs output using ap_log_error?
>>>>>>
>>>>>> Thanks,
>>>>>> Jim
>>>>>>
>>>>>>
>>>>>>
>>>>>>              
>>>>> Hi,
>>>>>
>>>>> I think that I've found out why I'm not seeing those log messages.  Apparently, if the server parameter is NULL, only APLOG_NOTICE message appear except for during startup.
>>>>>
>>>>> So, I have use a server for that parameter, e.g. r->server, BUT, in some cases, e.g., in a function like the response callback for libcurl, where the signature is pre-defined, and where there is no request_rec or server_rec among the parameters, how can I get ap_log_error to output anything (other than APLOG_NOTICE) messages?
>>>>>
>>>>> Thanks,
>>>>> Jim
>>>>>
>>>>>
>>>>>            
>>>> Again, if you have access to a request_rec structure, I'd use
>>>> ap_log_rerror.  Otherwise, use ap_log_perror.  Those have a better
>>>> consistency with logging, e.g. :
>>>>
>>>> ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, requestrec, "uri = %s",r->uri);
>>>> ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, pool, "creating config");
>>>>
>>>> Joe
>>>>
>>>>          
>>> Hi,
>>>
>>> I think that I'm not explaining the problem that I have very clearly :(...
>>>
>>> Per earlier thread, I'm using libcurl to make an HTTP GET request from my module.
>>>
>>> In order that my module can access the response to that GET request, I had to use a write callback function tha allows curl to t make the response available to my code.
>>>
>>>        
>> That does explain things.  Using libcurl in a situation like that
>> before, I ended up using the callback function data as a structure, and
>> you could (in theory) slap the same request_rec pointers into that
>> structure so that you also had them in the call back.
>>
>> Aside from that, you are correct, if you don't have access to the
>> request_rec/pool_t structures, ap_log_error works the best, but
>> r->server won't work, either.
>>
>> Are you using virtual hosts?  If so, did you check all of the logs?
>> using r->server might behave differently and end up logging messages
>> into a different log file if you have virtual hosts.
>>
>> Joe
>>      
>
> Hi,
>
> I was thinking about something similar to what you suggested, but I think that, for now, I'll just use APLOG_NOTICE for the ap_log_error() calls inside the callback.  These would mainly be for debugging anyway.
>
> Thanks,
> Jim
>    

Just a suggestion, then.

I'd suggest leaving those calls in, and surround them with #ifdef 
directives.  Then, rather than "removing" them when you finish the 
product, you simply remove a #define listed at the top and those calls 
don't get compiled in.  Makes it easier to also compile a debug-specific 
version, too.

Joe
--
http://www.silverhawk.net/

Re: "Best practices" or recommendations for logging from a module?

Posted by oh...@cox.net.
---- Joe Lewis <jo...@joe-lewis.com> wrote: 
> On 07/01/2012 01:53 PM, ohaya@cox.net wrote:
> > ---- Joe Lewis<jo...@joe-lewis.com>  wrote:
> >    
> >> On 07/01/2012 12:55 PM, ohaya@cox.net wrote:
> >>      
> >>> ---- ohaya@cox.net wrote:
> >>>
> >>>        
> >>>> ---- ohaya@cox.net wrote:
> >>>>
> >>>>          
> >>>>> ---- Joe Lewis<jl...@silverhawk.net>   wrote:
> >>>>>
> >>>>>            
> >>>>>> Jim, you could use the log_error funtion all the time. Log_perror javits
> >>>>>> logging associated with a pool, and log_rerror is for requests. If
> >>>>>> possible, use log_rerror, because it puts the up address, etc into the logs.
> >>>>>>
> >>>>>> Joe
> >>>>>> On Jul 1, 2012 10:56 AM,<oh...@cox.net>   wrote:
> >>>>>>
> >>>>>>
> >>>>>>              
> >>>>> Joe,
> >>>>>
> >>>>> Thanks!
> >>>>>
> >>>>> Jim
> >>>>>
> >>>>>            
> >>>> Hi,
> >>>>
> >>>> Oh, oh :(.
> >>>>
> >>>> I'm using:
> >>>>
> >>>> ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,<my message>);
> >>>>
> >>>> all over the place, and even though I have only one LogLevel in the httpd;conf, at the top level, set to "debug", I don't see those messages.
> >>>>
> >>>> The only ones I see are the ones that use APLOG_NOTICE.
> >>>>
> >>>> Why is this?  I thought that with LogLevel set to debug, that I should see all level msgs output using ap_log_error?
> >>>>
> >>>> Thanks,
> >>>> Jim
> >>>>
> >>>>
> >>>>          
> >>> Hi,
> >>>
> >>> I think that I've found out why I'm not seeing those log messages.  Apparently, if the server parameter is NULL, only APLOG_NOTICE message appear except for during startup.
> >>>
> >>> So, I have use a server for that parameter, e.g. r->server, BUT, in some cases, e.g., in a function like the response callback for libcurl, where the signature is pre-defined, and where there is no request_rec or server_rec among the parameters, how can I get ap_log_error to output anything (other than APLOG_NOTICE) messages?
> >>>
> >>> Thanks,
> >>> Jim
> >>>
> >>>        
> >> Again, if you have access to a request_rec structure, I'd use
> >> ap_log_rerror.  Otherwise, use ap_log_perror.  Those have a better
> >> consistency with logging, e.g. :
> >>
> >> ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, requestrec, "uri = %s",r->uri);
> >> ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, pool, "creating config");
> >>
> >> Joe
> >>      
> >
> > Hi,
> >
> > I think that I'm not explaining the problem that I have very clearly :(...
> >
> > Per earlier thread, I'm using libcurl to make an HTTP GET request from my module.
> >
> > In order that my module can access the response to that GET request, I had to use a write callback function tha allows curl to t make the response available to my code.
> >    
> 
> That does explain things.  Using libcurl in a situation like that 
> before, I ended up using the callback function data as a structure, and 
> you could (in theory) slap the same request_rec pointers into that 
> structure so that you also had them in the call back.
> 
> Aside from that, you are correct, if you don't have access to the 
> request_rec/pool_t structures, ap_log_error works the best, but 
> r->server won't work, either.
> 
> Are you using virtual hosts?  If so, did you check all of the logs?  
> using r->server might behave differently and end up logging messages 
> into a different log file if you have virtual hosts.
> 
> Joe


Hi,

I was thinking about something similar to what you suggested, but I think that, for now, I'll just use APLOG_NOTICE for the ap_log_error() calls inside the callback.  These would mainly be for debugging anyway.

Thanks,
Jim

Re: "Best practices" or recommendations for logging from a module?

Posted by Joe Lewis <jo...@joe-lewis.com>.
On 07/01/2012 01:53 PM, ohaya@cox.net wrote:
> ---- Joe Lewis<jo...@joe-lewis.com>  wrote:
>    
>> On 07/01/2012 12:55 PM, ohaya@cox.net wrote:
>>      
>>> ---- ohaya@cox.net wrote:
>>>
>>>        
>>>> ---- ohaya@cox.net wrote:
>>>>
>>>>          
>>>>> ---- Joe Lewis<jl...@silverhawk.net>   wrote:
>>>>>
>>>>>            
>>>>>> Jim, you could use the log_error funtion all the time. Log_perror javits
>>>>>> logging associated with a pool, and log_rerror is for requests. If
>>>>>> possible, use log_rerror, because it puts the up address, etc into the logs.
>>>>>>
>>>>>> Joe
>>>>>> On Jul 1, 2012 10:56 AM,<oh...@cox.net>   wrote:
>>>>>>
>>>>>>
>>>>>>              
>>>>> Joe,
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Jim
>>>>>
>>>>>            
>>>> Hi,
>>>>
>>>> Oh, oh :(.
>>>>
>>>> I'm using:
>>>>
>>>> ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,<my message>);
>>>>
>>>> all over the place, and even though I have only one LogLevel in the httpd;conf, at the top level, set to "debug", I don't see those messages.
>>>>
>>>> The only ones I see are the ones that use APLOG_NOTICE.
>>>>
>>>> Why is this?  I thought that with LogLevel set to debug, that I should see all level msgs output using ap_log_error?
>>>>
>>>> Thanks,
>>>> Jim
>>>>
>>>>
>>>>          
>>> Hi,
>>>
>>> I think that I've found out why I'm not seeing those log messages.  Apparently, if the server parameter is NULL, only APLOG_NOTICE message appear except for during startup.
>>>
>>> So, I have use a server for that parameter, e.g. r->server, BUT, in some cases, e.g., in a function like the response callback for libcurl, where the signature is pre-defined, and where there is no request_rec or server_rec among the parameters, how can I get ap_log_error to output anything (other than APLOG_NOTICE) messages?
>>>
>>> Thanks,
>>> Jim
>>>
>>>        
>> Again, if you have access to a request_rec structure, I'd use
>> ap_log_rerror.  Otherwise, use ap_log_perror.  Those have a better
>> consistency with logging, e.g. :
>>
>> ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, requestrec, "uri = %s",r->uri);
>> ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, pool, "creating config");
>>
>> Joe
>>      
>
> Hi,
>
> I think that I'm not explaining the problem that I have very clearly :(...
>
> Per earlier thread, I'm using libcurl to make an HTTP GET request from my module.
>
> In order that my module can access the response to that GET request, I had to use a write callback function tha allows curl to t make the response available to my code.
>    

That does explain things.  Using libcurl in a situation like that 
before, I ended up using the callback function data as a structure, and 
you could (in theory) slap the same request_rec pointers into that 
structure so that you also had them in the call back.

Aside from that, you are correct, if you don't have access to the 
request_rec/pool_t structures, ap_log_error works the best, but 
r->server won't work, either.

Are you using virtual hosts?  If so, did you check all of the logs?  
using r->server might behave differently and end up logging messages 
into a different log file if you have virtual hosts.

Joe

Re: "Best practices" or recommendations for logging from a module?

Posted by oh...@cox.net.
---- Joe Lewis <jo...@joe-lewis.com> wrote: 
> On 07/01/2012 12:55 PM, ohaya@cox.net wrote:
> > ---- ohaya@cox.net wrote:
> >    
> >> ---- ohaya@cox.net wrote:
> >>      
> >>> ---- Joe Lewis<jl...@silverhawk.net>  wrote:
> >>>        
> >>>> Jim, you could use the log_error funtion all the time. Log_perror javits
> >>>> logging associated with a pool, and log_rerror is for requests. If
> >>>> possible, use log_rerror, because it puts the up address, etc into the logs.
> >>>>
> >>>> Joe
> >>>> On Jul 1, 2012 10:56 AM,<oh...@cox.net>  wrote:
> >>>>
> >>>>          
> >>>
> >>> Joe,
> >>>
> >>> Thanks!
> >>>
> >>> Jim
> >>>        
> >>
> >> Hi,
> >>
> >> Oh, oh :(.
> >>
> >> I'm using:
> >>
> >> ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,<my message>);
> >>
> >> all over the place, and even though I have only one LogLevel in the httpd;conf, at the top level, set to "debug", I don't see those messages.
> >>
> >> The only ones I see are the ones that use APLOG_NOTICE.
> >>
> >> Why is this?  I thought that with LogLevel set to debug, that I should see all level msgs output using ap_log_error?
> >>
> >> Thanks,
> >> Jim
> >>
> >>      
> >
> > Hi,
> >
> > I think that I've found out why I'm not seeing those log messages.  Apparently, if the server parameter is NULL, only APLOG_NOTICE message appear except for during startup.
> >
> > So, I have use a server for that parameter, e.g. r->server, BUT, in some cases, e.g., in a function like the response callback for libcurl, where the signature is pre-defined, and where there is no request_rec or server_rec among the parameters, how can I get ap_log_error to output anything (other than APLOG_NOTICE) messages?
> >
> > Thanks,
> > Jim
> >    
> Again, if you have access to a request_rec structure, I'd use 
> ap_log_rerror.  Otherwise, use ap_log_perror.  Those have a better 
> consistency with logging, e.g. :
> 
> ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, requestrec, "uri = %s",r->uri);
> ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, pool, "creating config");
> 
> Joe


Hi,

I think that I'm not explaining the problem that I have very clearly :(...

Per earlier thread, I'm using libcurl to make an HTTP GET request from my module.  

In order that my module can access the response to that GET request, I had to use a write callback function tha allows curl to t make the response available to my code.

The signature for that function is:

size_t static write_callback_func(void *buffer,
                        size_t size,
                        size_t nmemb,
                        void *userp)

Curl doesn't "know" anything about the Apache structures like the server, pool, etc. and from that signature, there isn't a way to for my code to pass any of that through to the call back function, and since I can't do that, there doesn't seem to be a way that I can get any of the ap_log_xxx() functions to actually output anything to the Apache error log.

Hopefully, that's clearer explanation of the problem?

Jim


Re: "Best practices" or recommendations for logging from a module?

Posted by Joe Lewis <jo...@joe-lewis.com>.
On 07/01/2012 12:55 PM, ohaya@cox.net wrote:
> ---- ohaya@cox.net wrote:
>    
>> ---- ohaya@cox.net wrote:
>>      
>>> ---- Joe Lewis<jl...@silverhawk.net>  wrote:
>>>        
>>>> Jim, you could use the log_error funtion all the time. Log_perror javits
>>>> logging associated with a pool, and log_rerror is for requests. If
>>>> possible, use log_rerror, because it puts the up address, etc into the logs.
>>>>
>>>> Joe
>>>> On Jul 1, 2012 10:56 AM,<oh...@cox.net>  wrote:
>>>>
>>>>          
>>>
>>> Joe,
>>>
>>> Thanks!
>>>
>>> Jim
>>>        
>>
>> Hi,
>>
>> Oh, oh :(.
>>
>> I'm using:
>>
>> ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,<my message>);
>>
>> all over the place, and even though I have only one LogLevel in the httpd;conf, at the top level, set to "debug", I don't see those messages.
>>
>> The only ones I see are the ones that use APLOG_NOTICE.
>>
>> Why is this?  I thought that with LogLevel set to debug, that I should see all level msgs output using ap_log_error?
>>
>> Thanks,
>> Jim
>>
>>      
>
> Hi,
>
> I think that I've found out why I'm not seeing those log messages.  Apparently, if the server parameter is NULL, only APLOG_NOTICE message appear except for during startup.
>
> So, I have use a server for that parameter, e.g. r->server, BUT, in some cases, e.g., in a function like the response callback for libcurl, where the signature is pre-defined, and where there is no request_rec or server_rec among the parameters, how can I get ap_log_error to output anything (other than APLOG_NOTICE) messages?
>
> Thanks,
> Jim
>    
Again, if you have access to a request_rec structure, I'd use 
ap_log_rerror.  Otherwise, use ap_log_perror.  Those have a better 
consistency with logging, e.g. :

ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, requestrec, "uri = %s",r->uri);
ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, pool, "creating config");

Joe

Re: "Best practices" or recommendations for logging from a module?

Posted by oh...@cox.net.
---- ohaya@cox.net wrote: 
> 
> ---- ohaya@cox.net wrote: 
> > 
> > ---- Joe Lewis <jl...@silverhawk.net> wrote: 
> > > Jim, you could use the log_error funtion all the time. Log_perror javits
> > > logging associated with a pool, and log_rerror is for requests. If
> > > possible, use log_rerror, because it puts the up address, etc into the logs.
> > > 
> > > Joe
> > > On Jul 1, 2012 10:56 AM, <oh...@cox.net> wrote:
> > > 
> > 
> > 
> > Joe,
> > 
> > Thanks!
> > 
> > Jim
> 
> 
> Hi,
> 
> Oh, oh :(.
> 
> I'm using:
> 
> ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, <my message>);
> 
> all over the place, and even though I have only one LogLevel in the httpd;conf, at the top level, set to "debug", I don't see those messages.
> 
> The only ones I see are the ones that use APLOG_NOTICE.
> 
> Why is this?  I thought that with LogLevel set to debug, that I should see all level msgs output using ap_log_error?
> 
> Thanks,
> Jim
> 


Hi,

I think that I've found out why I'm not seeing those log messages.  Apparently, if the server parameter is NULL, only APLOG_NOTICE message appear except for during startup.

So, I have use a server for that parameter, e.g. r->server, BUT, in some cases, e.g., in a function like the response callback for libcurl, where the signature is pre-defined, and where there is no request_rec or server_rec among the parameters, how can I get ap_log_error to output anything (other than APLOG_NOTICE) messages?

Thanks,
Jim

Re: "Best practices" or recommendations for logging from a module?

Posted by oh...@cox.net.
---- ohaya@cox.net wrote: 
> 
> ---- Joe Lewis <jl...@silverhawk.net> wrote: 
> > Jim, you could use the log_error funtion all the time. Log_perror javits
> > logging associated with a pool, and log_rerror is for requests. If
> > possible, use log_rerror, because it puts the up address, etc into the logs.
> > 
> > Joe
> > On Jul 1, 2012 10:56 AM, <oh...@cox.net> wrote:
> > 
> 
> 
> Joe,
> 
> Thanks!
> 
> Jim


Hi,

Oh, oh :(.

I'm using:

ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, <my message>);

all over the place, and even though I have only one LogLevel in the httpd;conf, at the top level, set to "debug", I don't see those messages.

The only ones I see are the ones that use APLOG_NOTICE.

Why is this?  I thought that with LogLevel set to debug, that I should see all level msgs output using ap_log_error?

Thanks,
Jim


Re: "Best practices" or recommendations for logging from a module?

Posted by oh...@cox.net.
---- Joe Lewis <jl...@silverhawk.net> wrote: 
> Jim, you could use the log_error funtion all the time. Log_perror javits
> logging associated with a pool, and log_rerror is for requests. If
> possible, use log_rerror, because it puts the up address, etc into the logs.
> 
> Joe
> On Jul 1, 2012 10:56 AM, <oh...@cox.net> wrote:
> 


Joe,

Thanks!

Jim

Re: "Best practices" or recommendations for logging from a module?

Posted by Joe Lewis <jl...@silverhawk.net>.
Jim, you could use the log_error funtion all the time. Log_perror javits
logging associated with a pool, and log_rerror is for requests. If
possible, use log_rerror, because it puts the up address, etc into the logs.

Joe
On Jul 1, 2012 10:56 AM, <oh...@cox.net> wrote:

>
> ---- ohaya@cox.net wrote:
> > Hi,
> >
> > I'm working on my 1st module, and everything seems to be working so far.
>  At this point, since it's a first module, and I've been doing lots of
> debugging, mostly running Apache in single process mode (-k start -X), I've
> only been using printf to output various things.
> >
> > I am somewhat loath to remove some of the printf output, esp. since my
> module is still pretty raw (though working), but I'm starting to look into
> how I can switch from using printf to whatever is "normally" used for
> logging output from Apache modules.
> >
> > Given that I don't want to completely remove the ability to output the
> debug output, is there a best practice for logging from an Apache module?
>  Is it just to use the apr logging calls, and set the level to debug?
> >
> > Thanks,
> > Jim
> >
> >
> >
> >
>
>
> Hi,
>
> Also, I guess that, other than the functions take different parameters, I
> don't quite "get" why there are 4(?) different log functions
> (apr_log_error(), apr_log_rerror(), etc.).  Can I just use one of them all
> the time, e.g., apr_log_error()?
>
> Jim
>

Re: "Best practices" or recommendations for logging from a module?

Posted by oh...@cox.net.
---- ohaya@cox.net wrote: 
> Hi,
> 
> I'm working on my 1st module, and everything seems to be working so far.  At this point, since it's a first module, and I've been doing lots of debugging, mostly running Apache in single process mode (-k start -X), I've only been using printf to output various things.
> 
> I am somewhat loath to remove some of the printf output, esp. since my module is still pretty raw (though working), but I'm starting to look into how I can switch from using printf to whatever is "normally" used for logging output from Apache modules.
> 
> Given that I don't want to completely remove the ability to output the debug output, is there a best practice for logging from an Apache module?  Is it just to use the apr logging calls, and set the level to debug?
> 
> Thanks,
> Jim
> 
> 
> 
> 


Hi,

Also, I guess that, other than the functions take different parameters, I don't quite "get" why there are 4(?) different log functions (apr_log_error(), apr_log_rerror(), etc.).  Can I just use one of them all the time, e.g., apr_log_error()?  

Jim