|
From: Craig M. <C.M...@of...> - 2006-11-23 16:21:39
|
Hi,
Looking at the Log::Log4Perl code and it's suitability to be used in an
application framework I'm working on, I see that it can't be used
(safely) in multiple applications running within the same mod_perl
server. This is because even though these applications use there own
module namespaces, they obviously will clash with each other when
calling the init or init_once method.=20
I think a better design would be to make Log::Log4Perl descend from
Class::Singleton, store all variables that are now globals in the
instance, and let users optionally create subclassed versions of
Log::Log4Perl in there own namespaces.
E.g. you'ld get something like this:
=20
package AppX;
use AppX::Log4Perl; # descends from Log::Log4Perl
...
my $l4p =3D AppX::Log4Perl->instance();
$l4p->init_once('appx.conf');
my $logger =3D $l4p->get_logger();
=20
.... then in another application sharing the same httpd:
package AppY;
use AppY::Log4Perl; # descends from Log::Log4Perl
...
$l4p->init_once('appy.conf');
my $logger =3D $l4p->get_logger();
=20
=20
... and AppX::Log4Perl will look like exactly like this:
=20
package AppX::Log4Perl;
use strict;
use base(Log::Log4Perl);
1;
__END__
=20
=20
I know it will be a major change to build this into Log::Log4Perl but I
think it can be done while retaining backwards compatibility.
All current class methods now can be automatically turned into both
class and object methods at the same time like this:
sub a_class_method {
my $proto =3D shift;
my $self =3D ref($proto) ? $proto : $proto->instance();
}
Actually the magic above can become more involved if necessary.
=20
Log::Log4Perl is a great piece of work.... I only miss that.
=20
In general when making packages, one must really scratch one's head a
few times if deciding to use globals, because they are almost always
unnecessary (except for constants) and a simple object or else
Class::Singleton based alternative is almost always the solution.
=20
That's just my 2p.
=20
Regards,
Craig Manley.
|