First, you need to add the library, by double clicking your Model project, as you can see on your left hand side.
Second, you need to create a log4j.properties file within:
C:\...\Model\src
just like the following:
# Set root logger level to INFO and its only appender to ConsoleOut.
log4j.rootLogger=INFO, ConsoleOut
# ConsoleOut is set to be a ConsoleAppender.
log4j.appender.ConsoleOut=org.apache.log4j.ConsoleAppender
# ConsoleOut uses PatternLayout.
log4j.appender.ConsoleOut.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleOut.layout.ConversionPattern=%-5p: [%d] %c{1} - %m%n
log4j.logger.org.apache.jsp=DEBUG
#Addon for
com.sun.faces.level=FINE
Third, you edit your entity object code like that:
...
import org.apache.log4j.Logger;
public class ImagesImpl extends TuhraEntityImpl {
...
private Logger logger = Logger.getLogger(this.getClass());
...
private void adjustImageUsages(RowSet newImageUsagesBeforePost) {
...
if (logger.isDebugEnabled())
logger.debug("ImageUsages has been adjusted");
}
...
}
Finally the message you created appears in the log output window:
INFO : [2010-09-12 09:56:32,593] ImagesImpl - ImageUsages has been adjusted
Would you like to refactor?
Furthermore, if you use logging within multiple entity objects, you could move the declaration code line:
private Logger logger = Logger.getLogger(this.getClass());
to the super class:
package tuhra.model.framework;
import oracle.jbo.server.EntityImpl;
import org.apache.log4j.Logger;
public class TuhraEntityImpl extends EntityImpl {
protected Logger logger = Logger.getLogger(this.getClass());
}
Upon commit, the logger output appears once more:
INFO : [2010-09-16 10:28:07,288] ImagesImpl - ImageUsages has been adjusted
For dynamic changes of logging levels, one can consult for example:
dynamically-changing-log-level-with-weblogic-log4j-jmx-and-wlst/
Finally, if you need more tips about appenders:
http://www.mobilefish.com/developer/log4j/log4j_quickguide_appenders.html
https://logging.apache.org/log4j/2.x/