CSPEC issue: lossing scope (or incorrect scope) in cspec subroutine.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I've attempted to add a global spec to my logging configuration, and
it will not see the scope of which I would like it to.
If possible can you take a quite look at this and let me know if there
is a way to do this.

The general premise of this is that I have a top level package that
starts up my environment (in this case DBALL.pm).
Inisde of this library, I initialize and watch a standardized
configuration file, in which any other libraries are added as

I have a resource type of factory in this example of which returns a
newly instantiated object (in this case DBALL::TESTOBJECT).
Inside of this object I have set attributes that I would like to be
able to add to every log statement (I have done this via a cspec - of
which is not acting like I would like it to).
The cspec override is stipulated inside of DBALL.pm, and I would like
to reference the calling object (in this case DBALL::TESTOBJECT), but
it sees self as something coming from

I've added a if routine to dump out caller to let me know who's
calling the cspec, and it dumps that out for viewing.

If you are able, can you unzip this and run test.pl to see the output?

I will put them in line here as well, they are rudimentary, but they
can reproduce my problem easily.

Any help that you can provide would be great.


The log configuration file:

<<<< ./logger.conf >>>>
log4perl.rootLogger = INFO, ScreenApp
log4perl.appender.ScreenApp= Log::Log4perl::Appender::Screen
log4perl.appender.ScreenApp.stderr   = 0
log4perl.appender.ScreenApp.layout   = PatternLayout
log4perl.appender.ScreenApp.layout.ConversionPattern = %d %-5p %-4L %M
%U %m%n
log4perl.appender.ScreenApp.Threshold = TRACE
log4perl.logger.DBALL.RESOURCEFACTORY = INFO,ScreenApp
log4perl.logger.DBALL.TESTOBJECT = INFO, ScreenApp
log4perl.oneMessagePerAppender = 1
<<<< logger.conf >>>>

The test.pl file:

<<<< ./test.pl >>>>
#!/usr/bin/perl -w
use strict;
use DBALL;
my $object = DBALL::RESOURCEFACTORY->new();
print "DONE";
<<<<test.pl >>>>

<<<< ./DBALL.pm >>>>
package DBALL;

use lib "../DBALL";

use Module::Locate qw / locate /;
use File::Basename;
use Log::Log4perl;
use Data::Dumper;

    use Module::Locate qw / locate /;
    my $location = locate __PACKAGE__;
    my ($name,$path,$suffix) = fileparse($location,"\.pm");
    my $logConf = $path . "logger.conf";
    Log::Log4perl::Layout::PatternLayout::add_global_cspec( 'U',
        sub {
            if(defined($self->) && defined($self->)){
                return sprintf(" [%s:%s]", $self->, $self->
                print Dumper(caller(0));
                return " ERROR ";

            } );
    Log::Log4perl->init_and_watch($logConf, 3);
<<<< ./DBALL.pm >>>>

The resource factory file:

use strict;
use Log::Log4perl;

use lib "./DBALL";

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();

sub new {
    my($class, $args) = @_;
    my ($self, $factoryClass);
    $self = bless {}, $class;
    $self-> = Log::Log4perl::get_logger($class);
    eval "require DBALL::TESTOBJECT";
    return new DBALL::TESTOBJECT->new($args);

and finally the TESTOBJECT

<<<< ./DBALL/TESTOBJECT.pm >>>>
use strict;
use Log::Log4perl;

sub new {
    my($class, $args) = @_;
    my $self = bless {
        id => "TESTOBJECT",
        mgmt_ip => "",
        logger => undef,
    $self-> = Log::Log4perl::get_logger($class);
    $self->->info("REF: " . ref($self));
    $self->->info("CLASS: $class");
    return $self;
<<<< ./DBALL/TESTOBJECT.pm >>>>

Site Timeline