|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Portals Adding Logging to a WebSphere Portlet
Three Ways To Do It: Good, Better, and Best
May. 26, 2005 10:15 AM
Adding logging to portlet code is usually an afterthought during the development cycle. The issue of logging usually only comes up after a portlet has been deployed in production and an error occurs. Then you hear, "Well, the problem didn't happen during testing." This paper steps you through the three different logging mechanisms available for portlets. The first demonstrates the WebSphere Portal's built-in logging mechanism. The second is a roll-your-own version of the base WebSphere Portal logging. The third shows you how to add Log4j to your portlet. Add WebSphere PortletLog to a Basic Portlet Using the native WebSphere PortletLog logging for your portlet development has a few drawbacks. So you understand both its strengths and weaknesses, you can try this logging feature with the Test Log project. Open TestLogPortlet.java and add the declaration for the PortletLog and sClassName. Replace the init() [A], doView() [B] and actionPerformed() [C] methods with the code shown in Listing 1 at the end of this article. Remove the annotations [...] from the listing before you compile. Besides instantiating a reference to the PortletLog [D] in init(), the logging methods info() [E] and error() [F] are added to both doView() and actionPerformed(). To prevent a negative impact on performance always check to see if logging is enabled using if (logger.isInfoEnabled()) ... before invoking info(). Also limit the number of info() calls to significant events such as method entry and exit to prevent the portlet from spending more time tracing than actually performing its function. Since error() is only invoked under extraordinary circumstances, you don't need to check if error logging is enabled before invoking this method. Logging in the WebSphere Portal Server consists of three distinct levels and one all-encompassing level (all):
Although PortletLog supports different logging levels, the best rule for the PortletLog tracing is to keep the assignments simple. Limit your level assignments to all=enabled or all=disabled. Enabling PortletLog Tracing Using the Rational Software Development Platform Notice the port number. The portal login page for this test environment will have the address http://localhost:9081/wps/myportal. Click Next. Add Test LogEAR to the list of Configured projects. The WebSphere Portal Server test environment will display the portlet. In the Servers view, right click on the WebSphere Portal v5.0 Test Environment. Press Stop. After the server stops, right click on the server and select Open. Choose the Portal Options tab. Select the Enable base portlets for portal administration and customization and Enable console logging checkboxes. Press Ctrl-S to save your configuration changes and close the server configuration panel. Right click on the Test Log portlet project again and choose Run=>Run on server. Due to the design of PortletLog tracing, you need the administration console to enable portlet logging. Once the portlet renders, navigate to Administration=>Portal Analysis=>Enable Tracing. You enable tracing by adding the line org.apache.jetspeed.portlet.PortletLog=all=enabled to the Append these trace settings field. Press the plus (+) button. Log out of the portal and then logon. After the page with the Test Log portlet displays, press the Submit button and select the Console tab. You should see messages similar to those shown in Figure 5. Results of Using PortletLog Logging The benefit of using the PortletLog is that it's simple. It's included in the base portlet class. You can get a reference to the PortletLog using:
YOUR FEEDBACK
WEBSPHERE LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING WEBSPHERE NEWS
|
|||||||||||||||||||||||||||||||||||||