Topic
3 replies Latest Post - ‏2013-11-28T18:26:23Z by bourne
haagenhasle
haagenhasle
5 Posts
ACCEPTED ANSWER

Pinned topic Logging filter in Liberty

‏2013-11-20T08:26:02Z |

I'm trying to make a custom logging filter, as described here:

http://publib.boulder.ibm.com/infocenter/wsdoc400/v6r0/index.jsp?topic=/com.ibm.websphere.iseries.doc/info/ae/ae/rtrb_createfilter.html
(or almost as described here, the filter is actually used to customize the logging output, and add fields ala log4js MDC)

I've put the logging filter classes in a separate jar, and put this jar in a globalLibraryRef in the classloader for my application (along with some commons-logging and slf4j jars).  When I debug my application, I can see that the filter is set in the rootHandler (this is done in a servlet filter), but the isLoggable-method in the filter is never called.

The same code is working in WAS Full Profile, so I'm wondinger what I'm doing wrong.  Is it something about the classloading in Liberty that interferes?

Regards, Haagen

  • bourne
    bourne
    2 Posts
    ACCEPTED ANSWER

    Re: Logging filter in Liberty

    ‏2013-11-27T20:55:11Z  in response to haagenhasle

    Hi Haagen,

    Can you try starting from something simple/small to see if things works as expected, then build from there?  I'm picturing a simple .war that creates a Filter and a Handler, adds the Filter to the Handler, and does some logging via a JUL Logger.  Assuming all goes well, and your Filter is called as expected, add back in the layers, one at a time, to see which piece is causing things to break.

    Keep in mind also that in Liberty log/trace do not route through JUL like they do in full profile WAS -- so you should only expect to see JUL log/trace entries, and things routed to JUL, at your root handler's filter.

    Don

    • haagenhasle
      haagenhasle
      5 Posts
      ACCEPTED ANSWER

      Re: Logging filter in Liberty

      ‏2013-11-27T21:21:27Z  in response to bourne

      Could you please explain the part about "in Liberty log/trace do not route through JUL"?  I've obviously misunderstood something here.. :)  

      It says here (http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.wlp.nd.multiplatform.doc%2Fae%2Frwlp_logging.html) that "There is also interception of java.util.logging output."  This is what I must have misunderstood.  Liberty doesn't use JUL, but it intercepts JUL?  How exactly does this work?

      Is there any way to turn the table, and intercept the logging from Liberty Profile and route it through slf4j and logback?  

      What we are trying to achieve is logging certain information with every line (http://logback.qos.ch/manual/mdc.html).  I see from your name that you are the one who wrote the original JUL-filter for PDMT  to provide MDC-data in the log for WAS Full profile.  If you prefer, I can send you an email with more details.

      Regards, Haagen

      • bourne
        bourne
        2 Posts
        ACCEPTED ANSWER

        Re: Logging filter in Liberty

        ‏2013-11-28T18:26:23Z  in response to haagenhasle

        Haagen,

        To see better how this works, take a look at the picture on http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/topic/com.ibm.websphere.wlp.core.doc/ae/cwlp_HPELOverview.html

        Liberty (default) sends records from JUL through a handler that then passes the records to the log/trace service that sends info to the messages.log and trace.log. 

        Liberty (binary logging) is a bit different.  There records from the WAS Tr SPI are sent to the binary logging service directly (I believe it's actually incorrectly shown on the diagram that this goes through the JUL handler).

        So, in either case, you won't get all of the records by adding a JUL handler on Liberty.

        Going to your goal though -- adding info to every log/trace record, I have another answer you can consider, that is much simpler/cleaner than updating the records in your Log Filter.

        In WAS 8.5.5 and above, developers can use Binary Logging (BL -- basically the same technology as HPEL) to add custom extensions to log and trace records through the log record context API (com.ibm.websphere.logging.hpel.LogRecordContext).  BL includes any extensions present in the log record context on the logging thread when storing log and trace records.  For example, a developer might write a servlet filter to add important HTTP request parameters to the log record context.  While that servlet runs, BL would add those extensions to any log and trace records created on the same thread.

        You can then use the binaryLog command-line tool to filter records based on the content of log and trace record extensions.  Note that the advanced format shows the log/trace record extensions.

        For example...

        binaryLog view --includeExtension=myExtensionName=myExtensionValue --format=advanced

        [7/13/13 15:01:54:977 EDT] 00000078  1 UOW= source=com.ibm.ws.webcontainer.metadata class=com.ibm.ws.webcontainer.metadata.WebModuleMetaDataImpl method=getLocalTranConfigData() org= prod= component= thread=[Thread-63] myExtensionName=myExtensionValue
                  your message appears here
         

        Please feel free to email me (dbourne@ca.ibm.com), and I can send you sample code.