Apache-Voodoo
view release on metacpan or search on metacpan
lib/Apache/Voodoo/Debug/Log4perl.pm view on Meta::CPAN
package Apache::Voodoo::Debug::Log4perl;
$VERSION = "3.0200";
use strict;
use warnings;
use base("Apache::Voodoo::Debug::Common");
use File::Spec;
use Log::Log4perl;
use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 1;
$Log::Log4perl::caller_depth = 3;
#
# Since log4perl wants to use one config file for the whole running perl program (one
# call to init), and # ApacheVoodo lets you define logging per application (multiple inits).
# We're using a singleton to get around that. We append each config block to a hash and
# then init log4perl after the all the apps are loaded. Kinda ugly, but until log4perl supports
# multiple configs, then it's what we're stuck with.
#
our $self;
sub new {
my $class = shift;
my $id = shift;
my $conf = shift;
unless (ref($self)) {
$self = {};
$self->{conf} = {};
bless($self,$class);
}
if (ref($conf) eq "HASH") {
foreach (keys %{$conf}) {
$self->{conf}->{$_} = $conf->{$_};
}
}
elsif (!ref($conf)) {
$self->{v_file} = $conf;
}
return $self;
}
sub bootstrapped {
my $self = shift;
unless (Log::Log4perl->initialized()) {
my $conf;
if ($self->{v_file}) {
if (open(F,$self->{v_file})) {
local $/ = undef;
$conf = <F>;
$conf .= "\n";
close(F);
}
else {
warn $!
}
}
foreach (keys %{$self->{conf}}) {
$conf .= $_ .' = '.$self->{conf}->{$_}."\n";
}
Log::Log4perl->init_once(\$conf);
}
}
sub enabled {
( run in 0.484 second using v1.01-cache-2.11-cpan-39bf76dae61 )