geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: Geronimo 2/Log4j question
Date Thu, 13 Mar 2008 17:54:12 GMT
I've documented this a bit at http://cwiki.apache.org/confluence/ 
display/GMOxDOC21/Configuring+Application+Specific+Logging+with+Log4j

thanks
david jencks

On Mar 13, 2008, at 12:15 AM, David Jencks wrote:

> This gbean is now available in the 2.1.1-SNAPSHOT (branches/2.1)  
> and 2.2-SNAPSHOT (trunk) versions.  I also set up the apacheds  
> plugin plugins/directory/branches/1.0 to use g. 2.1.1-SNAPSHOT and  
> the new gbean to demonstrate segregating the apacheds logging to a  
> separate file.
>
> thanks
> david jencks
>
> On Mar 6, 2008, at 2:48 PM, David Jencks wrote:
>
>> After a little more thought I realized we could make this process  
>> more convenient by supplying a gbean.  See https:// 
>> issues.apache.org/jira/browse/GERONIMO-3898
>>
>> We need an example for the docs and to demonstrate that it works.
>>
>> If you don't want to switch to geronimo trunk here's the basic  
>> idea that you can implement in a listener:
>>
>>
>>     private static final String      CATEGORY_PREFIX =  
>> "log4j.category.";
>>     private static final String      LOGGER_PREFIX   =  
>> "log4j.logger.";
>>     private static final String      RENDERER_PREFIX =  
>> "log4j.renderer.";
>>
>>     public ApplicationLog4jConfigurationGBean(String  
>> log4jResource, String log4jFile, ServerInfo serverInfo,  
>> ClassLoader classloader) throws IOException {
>>         InputStream in;
>> //You won't have easy access to the serverInfo, so you should skip  
>> this part and use a resource inside your war file that you can  
>> load from the classloader
>>         if (log4jFile != null) {
>>             File file = serverInfo.resolveServer(log4jFile);
>>             in = new FileInputStream(file);
>>         } else if (log4jResource != null) {
>>             in = classloader.getResourceAsStream(log4jResource);
>>             if (in == null) {
>>                 throw new NullPointerException("No log4j  
>> properties resource found at " + log4jResource);
>>             }
>>         } else {
>>             return;
>>         }
>>         Properties props = new Properties();
>>         try {
>>             props.load(in);
>>         } finally {
>>             in.close();
>>         }
>>         //remove any global log4j configuration
>>         for (Iterator it = props.keySet().iterator(); it.hasNext 
>> (); ) {
>>             String key = (String) it.next();
>>             if (key.startsWith(CATEGORY_PREFIX)
>>                     || key.startsWith(LOGGER_PREFIX)
>>                     || key.startsWith(RENDERER_PREFIX)) {
>>                 continue;
>>             }
>>             it.remove();
>>         }
>>
>>         PropertyConfigurator.configure(props);
>>     }
>>
>> Hope this helps
>> david jencks
>>
>>
>>
>> On Mar 6, 2008, at 12:11 PM, David Jencks wrote:
>>
>>> You have to be careful about what properties you feed to  
>>> log4j..... I did get this approach working with the roller  
>>> plugin.  Look for the roller-custom.properties file in the  
>>> plugins/roller/trunk stuff
>>>
>>> have to run again, more later
>>>
>>> david jencks
>>>
>>> On Mar 6, 2008, at 11:52 AM, Adam Ruggles wrote:
>>>
>>>>
>>>> The problem with the ServletContextListener approach is that it  
>>>> takes over
>>>> the log4j for all apps.
>>>>
>>>> For instance, I have two web apps running in geronimo.  They  
>>>> share a common
>>>> code base.  I need each one to manage their own logging.  Right  
>>>> now using
>>>> the Listener approach, the following occurs.
>>>>
>>>> WebApp 1 starts up and begins logging com.my.package
>>>>
>>>> Everything looks good so far.
>>>>
>>>> WebApp2 starts up and begins logging com.my.package.  Now WebApp  
>>>> 1 is no
>>>> longer writing out to the log files and WebApp2's logs contains  
>>>> logging
>>>> information from WebApp1 and WebApp2.
>>>>
>>>> By the way in both cases the geronimo.log file is affected as well.
>>>>
>>>>
>>>> djencks wrote:
>>>>>
>>>>> The solution I know of is to include a log4j.properties file if  
>>>>> you
>>>>> want to run on servers that do not use log4j internally but to  
>>>>> have
>>>>> your ServletContextListener read an app specific properties  
>>>>> file that
>>>>> sets up the appender for your app and other such customizations  
>>>>> and
>>>>> feeds the info to log4j programatically.
>>>>>
>>>>> Roller uses this technique.
>>>>>
>>>>> I'm not sure exactly what the log4j API for this is and have to  
>>>>> run
>>>>> now, if you can't find it I can look more later.
>>>>> thanks
>>>>> david jencks
>>>>>
>>>>> On Mar 6, 2008, at 9:22 AM, Adam Ruggles wrote:
>>>>>
>>>>>>
>>>>>> I used Spring to create the listener like you've described here.
>>>>>> It works,
>>>>>> but the only problem is that I have multiple web apps and I'd  
>>>>>> like
>>>>>> them to
>>>>>> maintain their own log, however using this method causes the last
>>>>>> web app to
>>>>>> load to take over the logging.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Łukasz Budnik wrote:
>>>>>>>
>>>>>>> Hi!
>>>>>>>
>>>>>>> I had the very same problem with G2.0.0, currently I'm using
 
>>>>>>> G2.1 and
>>>>>>> to tell the truth I don't know whether this issue still exists
>>>>>>> because
>>>>>>> I use a very simple work around that works always and for my
 
>>>>>>> case is
>>>>>>> sufficient.
>>>>>>>
>>>>>>> Simply in WAR create a new class, implement the
>>>>>>> ServletContextListener
>>>>>>> interface and override contextInitialized method like this:
>>>>>>>
>>>>>>> public void contextInitialized(ServletContextEvent ctx) {
>>>>>>> 		String prefix = ctx.getServletContext().getRealPath("/");
>>>>>>> 		String file =
>>>>>>> ctx.getServletContext().getInitParameter("log4j-configuration-

>>>>>>> file");
>>>>>>> 		if (file != null) {
>>>>>>> 			DOMConfigurator.configure(prefix + "WEB-INF/" + file);
>>>>>>> 		}
>>>>>>> 	}
>>>>>>>
>>>>>>> it works in G2.0.0 and G2.1
>>>>>>>
>>>>>>> If You manage to use Log4j without this workaround, let me know
>>>>>>> please ;)
>>>>>>>
>>>>>>> best regards
>>>>>>> Łukasz
>>>>>>>
>>>>>>> On 27/02/2008, Jacek Laskowski <jacek@laskowski.net.pl>
wrote:
>>>>>>>> On Tue, Feb 5, 2008 at 11:10 AM, Adam Ruggles  
>>>>>>>> <a.ruggles@gmail.com>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>  I am also having this issue.  In tomcat I just needed
a
>>>>>>>>> log4j.xml in
>>>>>>>> my
>>>>>>>>>  classpath, however geronimo seems to ignore it.
>>>>>>>>>
>>>>>>>>>  The only solution I've found is to have Spring configure
 
>>>>>>>>> log4j
>>>>>>>> through the
>>>>>>>>>  web.xml but that takes over all logging in geronimo.
 I  
>>>>>>>>> need to
>>>>>>>>> have
>>>>>>>>>  separate logging for each of my web apps.
>>>>>>>>
>>>>>>>>  Have you tried to inverse-classloading and/or hidden-classes
>>>>>>>> elements
>>>>>>>>  in your plan so log4j and its configuration in Geronimo
is for
>>>>>>>>  Geronimo stuff and yours is for your stuff?
>>>>>>>>
>>>>>>>>  Jacek
>>>>>>>>
>>>>>>>>
>>>>>>>>  --
>>>>>>>>  Jacek Laskowski
>>>>>>>>  http://www.JacekLaskowski.pl
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> -- 
>>>>>> View this message in context: http://www.nabble.com/Geronimo-2-
>>>>>> Log4j-question-tp12865061s134p15879047.html
>>>>>> Sent from the Apache Geronimo - Users mailing list archive at
>>>>>> Nabble.com.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> View this message in context: http://www.nabble.com/Geronimo-2- 
>>>> Log4j-question-tp12865061s134p15882415.html
>>>> Sent from the Apache Geronimo - Users mailing list archive at  
>>>> Nabble.com.
>>>>
>>>
>>
>


Mime
View raw message