dwhitney has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,
I have a problem I was hoping the grand and glorious monks could help out with.
I have a script, calling a custom package, which starts up my Log4perl object.

The script calls: my $Obj = FakePackage->new();

Then in the package creates the Log4perl object like this: Log::Log4perl->init( $conf_path );

Now, with in the log config file, I have the following line:
log4perl.appender.LOGFILE.filename=sub { getLOGFILE(); }
(Yes the package contains the getLOGFILE subby)
in my conf file, and I keep getting the following error:

Undefined subroutine &main::getCLI_LOGFILE called at (eval 17) line 1 (#1) (F) The subroutine indicated hasn't been defined, or if it was, it has since been undefined.

I've tried using the __PACKAGE__ token and the FakePackage to access this sub, but I'll get the error...
Any thoughts to where I blew it?

Replies are listed 'Best First'.
Re: using subs in Log4perl config file
by saintmike (Vicar) on Oct 22, 2004 at 21:34 UTC
    First off, I've got to tell you that calling L4p->init() in a package is not recommended.

    init() should be called in the main program -- this is a L4p "best practice" to avoid you're loading several L4p-enabled modules, each of which clobbers the L4p configuration by calling init().

    Secondly, subroutines in the L4p config file are called in the main name space. If you want to call a sub in a different package, just fully qualify it, like SomePackage::getCLI_Logfile().

      Hello saintmike,
      OK, point one I'll correct now.
      I'm sitting here with the L4P doc's and FAQ and I must be blind or something...
      Anyway, thanks!

      Point 2, I've tried to explicitly state SomePackage::getCLI_Logfile() in the config, and it still bombs.
        Then you've either got a typo in the call to the function or you didn't pull in the package ("use SomePackage") it is contained in before calling init(). What's the error message?