Hi all,
based on Christian Hammers Issue #56 I have made some thoughts.
Currently, the initialization of Log4PHP is not objectoriented. Its
some procedural code at the of the Logger script.
Flow is that the script checks for some enviroment fields, creates the
f. e. Configurator class and calls configure on that.
The configurator class does its stuff and calls usually some static
Logger methods. F.e. the ConfiguratorIni is calling
the Logger::getHierarchy which is calling the LoggerHierarchy::singleton method.
You see, this is all quite confusing and complex.
The fields, which configure Log4PHP are deprecated in Log4J, stating
they are gonna to be private.
I think the good initialization would be something like this:
Logger::setConfiguraton('properties.xml');
Logger::setConfiguraton('MyClass');
Logger::initialize();
Logger::getLogger('mylogger');
The initialize() method can be done hidden by the first call of a
method like getLogger or getRootLogger or whatelse. It could be done
by default, but disabled by a flag for manual configuration.
This way we don't need the fields (except the "disable auto
initialization") anymore.
The Logger class should have an Hierarchy-Object (not this static
stuff anymore) in a static field. There is no need to have this all
this static way.
In the initialize method of Logger should happen something like that:
$this->hierarchy = new LoggerHierarchy();
$c = $this->getConfiguratorClass();
$c->configure($this->hierarchy);
That will avoid static calls in the Configurator like this:
$repository = Logger::getLoggerRepository();
return $configurator->doConfigure($url, $repository);
Any objections, thoughts?
Best,
Christian