https://bz.apache.org/bugzilla/show_bug.cgi?id=59232

            Bug ID: 59232
           Summary: Make the context name of an app available via JNDI
           Product: Tomcat 6
           Version: 6.0.44
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: 1983-01...@gmx.net

There are valid usecases where one must have access to the context name without
having access to the servlet context or servlet request. E.g., at Spring
configuration time or at Logback configuration time. The name is used to
construct the logging file name.

Example: 
<configuration>
  <!-- Add this -->
  <insertFromJNDI env-entry-name="java:comp/env/logback/contextName"
as="contextName" />
  <contextName>${contextName}</contextName>

  <appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <!-- Use here -->
    <file>${catalina.base}/logs/${CONTEXT_NAME}.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- or here -->
     
<fileNamePattern>${catalina.base}/logs/${CONTEXT_NAME}.log.%d.gz</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>
    […]
  </appender>

  <root level="INFO">
    <appender-ref ref="FILE" />
  </root>
[…]
</configuration>

Initially, I wrote a listener
(http://mo-tomcat-ext.sourceforge.net/xref/net/sf/michaelo/tomcat/extras/listeners/LogbackContextNameListener.html)
for that which does it's job for Logback in Tomcat 6. Tomcat 7+ needs some
refinements, different event type, parallel webapp version, nested context
path, etc.

I think, it is worthwhile having a generic approach to this and make it a
listener ContextNameListener available in Tomcat 7+ directly. StandardContext,
lines 6135+ has already some nice code how to properly convert all of this to a
filesafe context name.

I'd like to donate this code
(https://sourceforge.net/p/mo-tomcat-ext/code/HEAD/tree/tags/1.1/src/main/java/net/sf/michaelo/tomcat/extras/listeners/LogbackContextNameListener.java?format=raw)
to the project. It is already licensed under Apache License 2.0, and I am an
ASF member happily contributing it.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to