Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

different Log4perl configuration files in different web-apps under mod_perl

by Pickwick (Beadle)
on Jun 27, 2011 at 10:39 UTC ( [id://911540]=perlquestion: print w/replies, xml ) Need Help??

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

Hello all,

I have three different web applications which used to work under CGI only and got updated to work with mod_perl now. All three use Log4perl for logging with some own wrappers around it for historic reasons. All three applications have their own Log4perl configuration file, an example directory layout is as following:

cgi-bin/app1/log.conf cgi-bin/app2/log.conf cgi-bin/app3/log.conf

In a normal CGI environment Log4perl would get initialized on every request and because every request is handled by it's own perl process, no configuration data gets shared. Using mod_perl Log4perl is only initialized once and configuration data is shared among all requests to one and the same apache instance. The problem is that the configuration files are app specific, meaning that each configuration just defines a log file for the root logger without caring about it's app1 or 2 and now the log messages are saved in the file of the configuration of the app who gets requested first. Without mod_perl the configuration is pretty simple and easy to use, but with mod_perl the log messages get cluttered all over every configured log file depending on various things.

The only solution I see is to initialize Log4perl with one configuration file only for each and every application used with mod_perl and then define different loggers for all applications. This sounds pretty ugly to me, especially with applications of different vendors. I would prefer a CGI-like way, that every application comes with it's own Log4perl configuration file and on requests to the different applications Log4perl only uses the application specific configuration. But this would mean that one has to reinitialize Log4perl on every request, because there doesn't seem to be a way to not init it globally. Because I already have wrappers between the applications and Log4perl I could build something on my own which recognizes the application and determine if a new init is requeired or not. The only problem is that the init is global and one doesn't have just an instance or else which needs to be saved.

My questions:

  1. What are the best practices for Log4perl configurations with different applications under mod_perl at the same time? Even applications from different vendors.
  2. Is there any way to not init Log4perl on a per process basis, for example use it as an object instance which gets shared across different requests?
  3. Any other ideas on how to solve my problem besides using one configuration file for all applications?

Many thanks for any help!

P.S.: I already read How can I run Log::Log4perl under mod_perl? and those suggestions don't fit my needs. I need app specific configuration files and only care about concurrently writes to the same log files in the second place. Process specific log files identified by pid are useless in my opinion, because I can't know which request gets processed by which process and with threaded apache you don't even have those pids.

  • Comment on different Log4perl configuration files in different web-apps under mod_perl
  • Download Code

Replies are listed 'Best First'.
Re: different Log4perl configuration files in different web-apps under mod_perl
by danb (Friar) on Jun 27, 2011 at 16:04 UTC
    1. What are the best practices for Log4perl configurations with different applications under mod_perl at the same time? Even applications from different vendors.

    Use a single configuration file.

    2. Is there any way to not init Log4perl on a per process basis,

    Of course. Either use a mod_perl startup handler to run init(), or use Log4perl's init_once().

    , for example use it as an object instance which gets shared across different requests?
    Yes, but that wont give you separate configurations for each logger, all it does is saves the (very minimal) overhead of a get_logger() call.
    Any other ideas on how to solve my problem besides using one configuration file for all applications?
    Using a single configuration file is the only way that I know of.
Re: different Log4perl configuration files in different web-apps under mod_perl
by Anonymous Monk on Jun 27, 2011 at 10:55 UTC
Re: different Log4perl configuration files in different web-apps under mod_perl
by trwww (Priest) on Jun 28, 2011 at 04:33 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://911540]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found