[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Can you pass a Log4Perl logger between scripts?

Posted on 2012-09-18
Medium Priority
Last Modified: 2012-09-28
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 scriptA.pl and have it availabel to scriptB.pl

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');
$logger->info("Starting scriptA.pl");

my $rc = eval{scriptB.pl}; 

Open in new window

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

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

Open in new window

Is this possible, and if so, can someone provide a simple example.
Question by:Bbouch
LVL 28

Expert Comment

ID: 38410003
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.
LVL 85

Accepted Solution

ozo earned 2000 total points
ID: 38410704
our $logger = Log::Log4perl::get_logger('main');

my $rc = do'scriptB.pl';

Author Closing Comment

ID: 38444744
Sorry it took me so long to test this out. It works exactly as I needed.  Thank you, Ozo.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question