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.


In reply to different Log4perl configuration files in different web-apps under mod_perl by Pickwick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.