[Geoserver-users] Workaround for JBoss managed logging with GeoServer

Howdy:

Right now GeoServer does not work well in web application containers (like JBoss) that manage logging for all of its web apps. See:
http://jira.codehaus.org/browse/GEOS-1671

I have tested a workaround with GeoServer 1.6.4b and a JBoss 4.0.3SP1 instance that is configured to manage logging with log4j. Essentially, I modify GeoServer's WEB-INF/web.xml to run a very simple context listener that prevents GeoServer from taking control of logging.

Under this environment, the usual logging settings (i.e., the ones exposed to users in the web-based UI and ultimately services.xml) will not be consulted.

To implement this work-around:
1. Download:
http://jira.codehaus.org/secure/attachment/34967/SuppressLoggingConfigurationContextListener.class
Source code is at:
http://jira.codehaus.org/secure/attachment/34968/SuppressLoggingConfigurationContextListener.java

2. Put SuppressLoggingConfigurationContextListener.class into WEB-INF/classes/org/geoserver/logging/

3. Modify WEB-INF/web.xml to add this class to the listener list:
<listener>
<listener-class >org.geoserver.logging.SuppressLoggingConfigurationContextListener</listener-class>
</listener>
This should go after GeoserverInitStartupListener and LoggingStartupContextListener.

4. Restart your application container.

See below for the GeoServer-relevant settings that I use in my JBoss conf/log4j.xml file -- these roughly mimic the values found in DEFAULT_LOGGING.properties.

Cheers,
Ryan

    <!-- A time/date based rolling appender -->
    <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
       <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
       <param name="File" value="${jboss.server.home.dir}/log/${host.name}/server.log"/>
       <param name="Append" value="false"/>

       <!-- Rollover at midnight each day -->
       <param name="DatePattern" value="'.'yyyy-MM-dd"/>

       <layout class="org.apache.log4j.PatternLayout">
          <!-- The default pattern: Date Priority [Category] Message\n -->
          <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
       </layout>
    </appender>

   <logger name="org.geotools" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.geotools.factory" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.geoserver" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.vfny.geoserver" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.vfny.geoserver.config.web.tiles.definition.MultipleDefinitionsFactory" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.vfny.geoserver.global" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.springframework" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.apache.struts" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.acegisecurity" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>

Hi Ryan,

Thanks for the info!! I am sure this will be quite useful to others who use applications containers such as JBoss. Its a pity that GeoServer (actually the fault lies in GeoTools) is so naive about system logging.

Anyways, any chance you would be interested in updating our FAQ with this info?

-Justin

Ryan Hofschneider wrote:

Howdy:

Right now GeoServer does not work well in web application containers (like JBoss) that manage logging for all of its web apps. See:
http://jira.codehaus.org/browse/GEOS-1671

I have tested a workaround with GeoServer 1.6.4b and a JBoss 4.0.3SP1 instance that is configured to manage logging with log4j. Essentially, I modify GeoServer's WEB-INF/web.xml to run a very simple context listener that prevents GeoServer from taking control of logging.

Under this environment, the usual logging settings (i.e., the ones exposed to users in the web-based UI and ultimately services.xml) will not be consulted.

To implement this work-around:
1. Download:
http://jira.codehaus.org/secure/attachment/34967/SuppressLoggingConfigurationContextListener.class
Source code is at:
http://jira.codehaus.org/secure/attachment/34968/SuppressLoggingConfigurationContextListener.java

2. Put SuppressLoggingConfigurationContextListener.class into WEB-INF/ classes/org/geoserver/logging/

3. Modify WEB-INF/web.xml to add this class to the listener list:
<listener>
<listener- class >org.geoserver.logging.SuppressLoggingConfigurationContextListener</ listener-class>
</listener>
This should go after GeoserverInitStartupListener and LoggingStartupContextListener.

4. Restart your application container.

See below for the GeoServer-relevant settings that I use in my JBoss conf/log4j.xml file -- these roughly mimic the values found in DEFAULT_LOGGING.properties.

Cheers,
Ryan

    <!-- A time/date based rolling appender -->
    <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
       <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
       <param name="File" value="${jboss.server.home.dir}/log/$ {host.name}/server.log"/>
       <param name="Append" value="false"/>

       <!-- Rollover at midnight each day -->
       <param name="DatePattern" value="'.'yyyy-MM-dd"/>

       <layout class="org.apache.log4j.PatternLayout">
          <!-- The default pattern: Date Priority [Category] Message\n -->
          <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
       </layout>
    </appender>

   <logger name="org.geotools" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.geotools.factory" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.geoserver" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.vfny.geoserver" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.vfny.geoserver.config.web.tiles.definition.MultipleDefinitionsFactory " additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.vfny.geoserver.global" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.springframework" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.apache.struts" additivity="false">
         <level value="WARN"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>
   <logger name="org.acegisecurity" additivity="false">
         <level value="INFO"/>
         <appender-ref ref="geoserver-appender"/>
   </logger>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

!DSPAM:4007,4846f31b220331961014482!

--
Justin Deoliveira
The Open Planning Project
jdeolive@anonymised.com

Justin Deoliveira ha scritto:

Hi Ryan,

Thanks for the info!! I am sure this will be quite useful to others who use applications containers such as JBoss. Its a pity that GeoServer (actually the fault lies in GeoTools) is so naive about system logging.

Actually it's our fault, not GeoTools one. The problem started occurring
when we switched to log4j based logging.
In GeoServer we "own" logging, that is, we reset its configuration and
change it at runtime. This allows you to change the logging configuration from the UI.

In 1.5.x times we used java logging directly, and that's what
we were resetting and reconfiguring. Since almost no one is using
java logging, nobody noticed.

Since 1.6.x we back our logging onto log4j, meaning we do reset
and reconfigure log4j instead of java logging. The reset and reconfigure
theoretically should hit a GeoServer private copy of log4j, it should
work in "isolation", but since log4j ships as a shared library in JBOss,
our configuration actions end up impacting the whole server.

Anyways, most applications do ship with a log4j configuration file
in their classpath... I guess in JBoss that file is plainly ignored
since the server already has configured log4j, but I'm not sure.
Ryan, do you know more? Is there any supported way to configure
log4j logging "per application" in JBoss?

Cheers
Andrea

Andrea Aime ha scritto:

Justin Deoliveira ha scritto:

Hi Ryan,

...

Since 1.6.x we back our logging onto log4j, meaning we do reset
and reconfigure log4j instead of java logging. The reset and reconfigure
theoretically should hit a GeoServer private copy of log4j, it should
work in "isolation", but since log4j ships as a shared library in JBOss,
our configuration actions end up impacting the whole server.

This discussion on TheServerSide is quite on topic:
http://www.theserverside.com/discussions/thread.tss?thread_id=29870

However, most of the solutions in that thread seem to be JBoss specific.
The RepositorySelector approach seems a viable alternative, thought
not trivial to implement.
Unfortunately I cannot get to the article explaining how to use it on:
http://www.qos.ch/logging/sc.jsp

There is also this issue still open on the JBoss bug tracker:
http://jira.jboss.org/jira/browse/JBAS-1313;jsessionid=DCDCA2174758FDAF5A6F0C547B4DDE82?page=comments

Ryan, you might want to open a jira issue about this as well.

Cheers
Andrea

On Jun 4, 2008, at 5:06 PM, Justin Deoliveira wrote:

Anyways, any chance you would be interested in updating our FAQ with this info?

Sure thing:
http://geoserver.org/pages/viewpage.action?pageId=6586389

On Jun 5, 2008, at 1:18 AM, Andrea Aime wrote:

Is there any supported way to configure
log4j logging "per application" in JBoss?

Yup. You found the main way to do it (through RepositorySelector), which is also discussed on:
http://wiki.jboss.org/wiki/Log4jRepositorySelector via
http://wiki.jboss.org/wiki/Logging

The JBoss wiki also mentions, but does not really recommend:
http://wiki.jboss.org/wiki/ClassLoaderScoping

I briefly mention both of these approaches in the FAQ page.

The preference for me, incidentally, is to leave logging control to JBoss.

Cheers,
Ryan