[
https://issues.apache.org/jira/browse/LOG4PHP-168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13202134#comment-13202134
]
Emmet O'Grady commented on LOG4PHP-168:
---------------------------------------
Ok, its a problem with the documentation then:
http://logging.apache.org/log4php/docs/configuration.html
Near the very end of the page is says that you can pass an instance. The
comments in the code of the Logger class seem to suggest that passing an
instance is possible too.
Just out of interest, is that $config variable in your code above inserted into
the Configurator object as the $input array? Eg:
LoggerConfiguratorPhp::configure(LoggerHierarchy $hierarchy, $input = null)
I need to configure Log4php programatically as suggested in the docs but my
problem is that I can't insert custom variables into the configurator. I'd like
to avoid constants or global variables. If I could pass the configurator
instance to the Logger::config() function it would work perfectly because I
would have passed my custom variables through the $input array of the
Configurator::configure($heirarchy, $input) function. Is there any other way of
passing custom variables to the configurator?
> Passing an instance of a configurator class to the Logger::configure function
> gives an error
> --------------------------------------------------------------------------------------------
>
> Key: LOG4PHP-168
> URL: https://issues.apache.org/jira/browse/LOG4PHP-168
> Project: Log4php
> Issue Type: Bug
> Components: Code
> Affects Versions: 2.0
> Environment: Mac 10.6.8, PHP 5.3.6, Log4php v2.0 from the PEAR
> repository.
> Reporter: Emmet O'Grady
> Labels: configuration
>
> I get the following error when I try to pass a configurator object to the
> Logger::configure() function:
> PHP Warning: class_exists() expects parameter 1 to be string, object given
> in /var/pear/share/pear/log4php/Logger.php on line 586
> The function where this error is happening is the following:
> /**
> * Creates a logger configurator instance based on the provided
> * configurator class. If no class is given, returns an instance of
> * the default configurator.
> *
> * @param string $configuratorClass The configurator class.
> */
> private static function getConfigurator($configuratorClass = null) {
> if (empty($configuratorClass)) {
> return new LoggerConfiguratorDefault();
> }
>
> if (!class_exists($configuratorClass)) {
> $this->warn("Specified configurator class
> [$configuratorClass] does not exist. Reverting to default configurator.");
> return new LoggerConfiguratorDefault();
> }
>
> $configurator = new $configuratorClass();
>
> if (!($configurator instanceof LoggerConfigurator)) {
> $this->warn("Specified configurator class
> [$configuratorClass] does not implement the LoggerConfigurator interface.
> Reverting to default configurator.");
> return new LoggerConfiguratorDefault();
> }
>
> return $configurator;
> }
> I believe that there is a newer release of Log4php already out. If this bug
> is fixed in the new release then maybe it's time to update the PEAR repo.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira