Can you pass a Log4Perl logger between scripts?

I have a wrapper script that is going to call 1 to many other scripts and I would like to use Log4Perl to handle the logging for this process.

I can't seem to find a way to create a logger in and have it availabel to

I can have both scripts read the same conf file and get the same logger, but that seems like a poor way to accomplish what I am trying to do.

To be clear, I am not talking about subroutines or modules, but rather an eval{} or system()call to another perl script, so something along the lines of :

my $conf_file = './log4perl.props';
Log::Log4perl->init( $conf_file );
my $logger = Log::Log4perl::get_logger('main');

my $rc = eval{}; 

Open in new window

then in I was hoping to be able to just have logging lines as needed:

$logger->info("Now I'm in \n");

Open in new window

Is this possible, and if so, can someone provide a simple example.
Who is Participating?
ozoConnect With a Mentor Commented:
our $logger = Log::Log4perl::get_logger('main');

my $rc = do'';
Nope, won't work that way.

You're only talking about 2 lines of code that need to be added to each of the other scripts.  If there is some obscure way to accomplish what you want, it will certainly be far more than these 2 lines of code.
BbouchAuthor Commented:
Sorry it took me so long to test this out. It works exactly as I needed.  Thank you, Ozo.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.