Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1437

Attempting to log session ID throws if session not set

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.2.3
    • logback-access
    • None
    • Tomcat 8.5
      Oracle JDK 1.8
      Logback 1.2.3 (although it appears that the code in 1.3.0-alpha has the same problem)

    Description

      With a simple web-app that does not automatically create a session, using the following pattern in logback-access.xml:
      {code:xml}
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
          <encoder>
            <pattern>%h %l %u %user %date "%r" %s %b %sessionID</pattern>
          </encoder>
        </appender>
      {code}

      will cause the following exception:

      {code}
      20:22:26,782 |-ERROR in ch.qos.logback.core.ConsoleAppender[STDOUT] - Appender [STDOUT] failed to append. java.lang.IllegalStateException: Cannot create a session after the response has been committed
          at java.lang.IllegalStateException: Cannot create a session after the response has been committed
          at     at org.apache.catalina.connector.Request.doGetSession(Request.java:3030)
          at     at org.apache.catalina.connector.Request.getSession(Request.java:2451)
          at     at ch.qos.logback.access.spi.AccessEvent.getSessionID(AccessEvent.java:249)
          at     at ch.qos.logback.access.pattern.SessionIDConverter.convert(SessionIDConverter.java:21)
      ...
      {code}

      I believe that you can resolve this by changing AccessEvent.getSession() to call getSession(false) rather than getSession().

      Attachments

        Activity

          People

            logback-dev Logback dev list
            kdgregory Keith Gregory
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: