Can you pass a Log4Perl logger between scripts?

Posted on 2012-09-18
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 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.
Question by:Bbouch
    LVL 28

    Expert Comment

    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 84

    Accepted Solution

    our $logger = Log::Log4perl::get_logger('main');

    my $rc = do'';
    LVL 1

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    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…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now