Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ap_log_error not logging in my apache module

Tags:

c

logging

apache

I have this code in an apache module I'm working on, which is registered using ap_hook_child_init():

static class_name *mc;

static void child_init(apr_pool_t *pool, server_rec *s)
{
    ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "this pointer should be null: %pp", mc);
    mc  = mc_alloc();
    ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "this pointer should not be null: %pp", mc);
}

The problem: I am not seeing these log messages!

I am certain that this function is being called and that the call to mc_alloc() is working because when I log from other parts of the modules (like in the request handler), I see the log messages and get a valid result for the pointer. This also tells me that logging is working.

Is it my code that is wrong or my expectations? Can one not issue a log message during an ap_hook_child_init callback? If not, how else might I log that a child was init'ed?

like image 244
mlibby Avatar asked Jun 09 '12 14:06

mlibby


1 Answers

So it turns out that this wasn't a code problem, it was a configuration problem.

In /etc/apache2/sites-enabled/my_site.conf I had set LogLevel Info in my <VirtualHost> section, which apparently does not set it for the whole server.

I discovered this by changing from APLOG_INFO to APLOG_CRIT. Once I did that the messages appeared in the log. So I knew the server was properly logging and my code was working.

This lead me to believe that there were separate possible LogLevel settings and that I had probably been too specific with where mine was. Adding a LogLevel Info directive outside the <VirtualHost> section apparently was needed to set the whole server to log more messages than the default.

like image 134
mlibby Avatar answered Sep 28 '22 00:09

mlibby