You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-user@logging.apache.org by Andrew Wegner <an...@andrewwegner.com> on 2010/01/06 21:33:22 UTC

Set Logging Options at Runtime

According to http://incubator.apache.org/log4php/docs/configuration.html :
"The Log4PHP environment is fully configurable programmatically."

I have a PHP application containing multiple modules and various settings
within each module. I'd like to enable logging using log4php, but each
individual module has different settings (ie. Log level, log file, etc).
Some of these settings need to be changed on the fly by end users (log
level), and I'd like to store these properties in the database.

Right now I can set loglevel dynamically. I can not determine how to set
other properties dynamically though. Documentation on the configuration of
log4php is almost exclusively done via properties/xml files - though it says
all settings can be changed programmatically.

Has any done something like this? If so, how do I do so? I've looked through
the documentation at http://incubator.apache.org/log4php/index.html, but I
need more assistance.

To clarify - I do NOT want to use configuration files, as the end users will
not have direct access to these. I will provide a front end to change
certain logging settings, and all settings will be stored in the database.

Where can I find documentation on how to set various aspects of the logging
within the program?

Thank you,

Andrew Wegner

Re: Set Logging Options at Runtime

Posted by Christian Grobmeier <gr...@gmail.com>.
Hi Andrew,

> Some of these settings need to be changed on the fly by end users (log
> level), and I'd like to store these properties in the database.

first which came into my mind was that you probably need to write a
configurator. If you look into the configurators folder, you'll see
LoggerConfiguratorIni / XML etc.. If you want to configure out from a
database, then you'll probably want to implement the
LoggerConfigurator interface.
This is for "per request changes".

> Right now I can set loglevel dynamically. I can not determine how to set
> other properties dynamically though. Documentation on the configuration of
> log4php is almost exclusively done via properties/xml files - though it says
> all settings can be changed programmatically.

I think you are now speaking of "change properties within one single
request". In that case you probably want to do something like this
(out of my mind, not a clue if it works :-)):

$logger = Logger::getLogger('myLogger');
$appender = $l->getAppender('yourappendersname');
// assuming that you want to do somehting on a mail appender
$appender->setSubject('new subject');

You also could do:
$logger->setLevel(...);

> To clarify - I do NOT want to use configuration files, as the end users will
> not have direct access to these. I will provide a front end to change
> certain logging settings, and all settings will be stored in the database.

OK - if you are accepting that changes can be done "per request" only,
then you should go with a configurator implementation.

> Where can I find documentation on how to set various aspects of the logging
> within the program?

Besides online docs, there is only sourcecode. Please let me know if a
Configurator does help you. On this list you will get  help if you
need some more.

Best,
Christian


>
> Thank you,
>
> Andrew Wegner
>
>