Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • IBM Web Experience Factory wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category Web Experience Factory 8 Documentation WebSphere Portlet Factory 7 Documentation WebSphere Portlet Factory 7.0.1 Documentation Custom Search Scope...
Search
Community Articles > Web Experience Factory > Best Practices for Web Experience Factory > Custom Logging with log4j
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

bosox 2
Contribution Summary:
  • Articles authored: 6
  • Articles edited: 11
  • Comments Posted: 3

Recent articles by this author

Rich Data Definition - Add a select

This article explains the steps for specifying a paricular input control in a Rich Data Definition (RDD). The article and example are for a select builder, but the same steps can be used for adding any control to a RDD.

Date Time Formatting with Rich Data Definition (RDD)

This article illustrates how to format dates using a Rich Data Definition builder (RDD).

Custom Logging with log4j

This article talks about several different ways to do some logging with log4j. It also describes how to configure your own custom logging. Use SystemOut actions in an Action list. Use Debug Tracing builder Use the com.bowstreet.appserver.logmanager package Create your own custom logging

Use ...

Rich Data Definition - multiple schemas

How can you combine data defintions from two schemas into a single Rich Data Definition file?

If you want to add data definitions for multiple schemas to a Rich Data Defintion file, this sample will provide some insight. Install the WebSphere Portlet Factory Archive that is attached to ...

Property Broker Chained

Sample description

This sample shows you how to use IBM® WebSphere® Portlet Factory to implement inter-portlet communication using the property broker. More specifically, the sample shows how to chain portlets together. This means that a value is passed from the source to a target. ...

Community articleCustom Logging with log4j

Added by bosox 2 | Edited by IBM contributor bosox 2 on June 15, 2009 | Version 7
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: Best practices, Debugging, Troubleshooting, Logging

This article talks about several different ways to do some logging with log4j.  It also describes how to configure your own custom logging.

  • Use SystemOut actions in an Action list. 
  • Use Debug Tracing builder
  • Use the com.bowstreet.appserver.logmanager package
  • Create your own custom logging

Use SystemOut actions in an Action list

This technique is good for logging messages from an Action List builder.  It's a quick way to check the value of a variable or to log a message to help trace where you are in the application flow.  You can also turn off the logging for all SystemOut actions in your application by setting a single property.  This is much better than having to got back and comment out or delet many calls to System.out.println() in your code. 

The log entries are written to SystemOut.log and WEB-INF\logs\general.txt

In your action list, click the button to bring up the picker.  Select Special > SystemOut

 

Enter a message or use the picker to select an indirect reference that you want to log a value for.

To diable the SystemOut actions in all the actions lists for your Web Application, edit the log4j.properties file and change the following line from

log4j.logger.bowstreet.system.out=

INFO

to

log4j.logger.bowstreet.system.out=

WARN

Use Debug Tracing builder

Use the Debug Tracing builder to trace actions or the values of indirect references.  You can add as many Debug Tracing builders to the model as you like and trace as many actions or variable values as you like.  The logging is controled by an entry in the log4j.properties file.  So you can easily turn the logging on and off by setting a single property.  Keep in mind when setting that property that it control the logging from Debug Tracing builders in all the models for that Web Application.

The logging is written to \WEB-INF\logs\debugTracing.txt

Add a Debug Tracing builder to the model.

Select to trace all actions.

Go to the "Additional Debug Output" input field.  Select an indirect reference to log using the picker

Edit the log4j.properties file and change the following line from

log4j.logger.bowstreet.system.debugTracing=

INFO,DebugTracing

to

log4j.logger.bowstreet.system.debugTracing=

DEBUG,DebugTracing

Use the com.bowstreet.appserver.logmanager package

Use this package to log messages from your Portlet Factory Linked Java Objects.  You can add calls to your code that use this package and log messages and variable values to SystemOut.log and \WEB-INF\logs\general.txt. 

This logging is written to SystemOut.log and WEB-INF\logs\general.txt.

Add a call to such as the following to log a message:

            LogEvent.writeLogEntry(Severity.ALL, Component.ALL,"message from logmanager");

This property in the log4j.properties file controls when your messages get
logged. 

# this corresponds to the previous Event drivers
log4j.logger.bowstreet.system.server.logging.event=WARN,Server

Whether or not a message is logged depends on the severity you use in the writeLogEntry() method and the severity set for the property in log4j.properties.

For example with the default setting of WARN, messages that have a severity
of ALL, SEVERE, ERROR and WARNING will be logged.  Messages that have a
severity of DEBUG or INFORMATION will not be logged.

Create your own custom logging

The last technique involves creating your own logging class and appender information.  The word "class" in this case does not refer to a Java class.  The word class in this case is specific to logging.  The advantage of creating your own logging classes is that you can make your logging more granular.  You can have a logging class for each Java class you want to debug or you can have a logging class for each package or use your own design.

The output of your logging can be logged to any file you choose.  This is configured in the log4j.properties file.  Add the lines below and simply change the value of the property "log4j.appender.MyLogging.File".

#


 The custom appender sends its ouput to myLogging.txt

log4j.appender.MyLogging=

org.apache.log4j.FileAppender

log4j.appender.MyLogging.File=

${bowstreet.rootDirectory}/logs/myLogging.txt

# Truncate the logging file if it aleady exists.

log4j.appender.MyLogging.Append=

true

# Appender MyLogging uses the PatternLayout.

log4j.appender.MyLogging.layout=

org.apache.log4j.PatternLayout

log4j.appender.MyLogging.layout.ConversionPattern=

*-- TIME: [%d] --* %nCategory: %c%nPriority: %p%nThread: %t%nMsg: %m%n%n%n

In your code, define a logger.

static Logger logger = Logger.getLogger("com.ibm.test.LoggingTest");

Then call methods on the logger in order to write log entries.  You can call debug(), info(), warn(), error() or fatal() to log messages of different severities.

logger

.debug("In setValue and the value is "+value);

Lastly, you will need to define the logging class in the log4j.properties file.  Since the name of the logging class above is "com.ibm.test.LoggingTest" and the appender is defined as "MyLogging", you will need to add the following line:

log4j.logger.com.bim.test.LoggingTestÞBUG,MyLogging

A sample Java Class and model are attached to demonstarte the custom logging.  Add the lines described above to try the sample.

expanded Attachments (0)
collapsed Attachments (0)
expanded Versions (17)
collapsed Versions (17)
Version Comparison     
VersionDateChanged by              Summary of changes
17Jan 14, 2010 3:08:40 PMR Flynn  IBM contributor
16Jan 14, 2010 3:07:50 PMR Flynn  IBM contributor
15Jan 14, 2010 3:07:18 PMR Flynn  IBM contributor
14Jan 12, 2010 2:35:07 PMRob Flynn  IBM contributor
13Jan 6, 2010 9:47:48 AMRob Flynn  IBM contributor
12Jan 5, 2010 9:55:09 AMRob Flynn  IBM contributor
11Jan 5, 2010 9:47:29 AMRob Flynn  IBM contributor
10Jan 5, 2010 9:45:22 AMRob Flynn  IBM contributor
9Dec 22, 2009 10:22:10 AMRob Flynn  IBM contributor
8Dec 22, 2009 10:19:51 AMRob Flynn  IBM contributor
This version (7)Jun 15, 2009 3:34:50 PMbosox 2  IBM contributor
6Jun 15, 2009 3:31:34 PMbosox 2  IBM contributor
5Jun 15, 2009 3:27:32 PMbosox 2  IBM contributor
4Jun 12, 2009 6:02:22 PMbosox 2  IBM contributor
3Jun 12, 2009 3:41:21 PMbosox 2  IBM contributor
2Jun 12, 2009 3:33:20 PMbosox 2  IBM contributor
1Jun 12, 2009 3:22:53 PMbosox 2  IBM contributor
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • BlogsIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use