Thank you for visiting! If you liked the site, please add a bookmark, else add a critical comment! Would you like to visit Greece? Traditional Greek flag This real estate site is only available in Greek! The holy mountain

Saturday 11 September 2010

JDeveloper 11g:Using Log4j in a JSF backing bean

Another example which might prove useful to JSF or ADF developers,  is logging within a backing bean.
First, you need to add the Log4j.jar by double clicking the ViewController project. You can see the library window on your left handside, showind the jar already added. Note that you can use logging via log4j in combination with ADFLogger, that is if you are using ADF, or even without it.

Second, you need to create the log4j.properties file in ViewController/src. Another  log4j.properties sample file is given here, for your convenience:


# 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 need to code! The example bean code follows:
...
import org.apache.log4j.Logger;
...
public class ImageUploadBean extends TuhraBackingBean implements Serializable {
  private Logger logger = Logger.getLogger(this.getClass());
 
...
 private void insertRows() {
...
    if (logger.isDebugEnabled())
       logger.debug("Succeeded in adding new image!");
    }
}

Finally, your message appears in the log window:

INFO : [2010-09-11 21:47:52,005] ImageUploadBean - Succeeded in adding new image!

Would you like to refactor?

Furthermore, if you use logging in several beans, you could move the declaration code line:

private Logger logger = Logger.getLogger(this.getClass());
 


to the super class TuhraBackingBean:

package tuhra.view.framework;

import oracle.adf.model.BindingContext;

import oracle.binding.BindingContainer;

import org.apache.log4j.Logger;

/**the purpose of this framework class is to
access the commonly used properties.
 */
public abstract class TuhraBackingBean {
   
    protected Logger logger = Logger.getLogger(this.getClass());
 
  /**the purpose of this framework method is to
  access the bindings programmatically.
   */
    public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }
}

Then the log outputs once more:
INFO : [2010-09-16 09:46:37,767] TuhraServiceImpl - New image has been created!
INFO : [2010-09-16 09:46:37,767] ImageUploadBean - Succeeded in adding new image!


where the first info message comes from the application module code (this could be another example I suppose!), while the second from the aforementioned backing bean. You could follow more or less the same steps for JDeveloper 10g too.
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/ 

Beware of Greeks Bearing Bonds Business: vanityfair.com

This is an article written by a journalist, who actually visited Greece to see for himself. He saw quite a lot, even if he only stayed for a while, unlike the Greek politicians who have been ruling for decades! Go ahead: Beware of Greeks Bearing Bonds Business: vanityfair.com

Thursday 9 September 2010

Comments on Project Management Body of Knowledge, PMI

On  the bright side, the text is well written,  in American English and  neatly organized, without any misspellings or errors. Its style is formal and actually contains all there is to know, in order to sit for the project management institute examinations. Its scope is by far more general than the compTIA Project + exam guide, which  focuses mainly on IT projects. The forth edition is revised and now includes new additions, such as requirements gathering.
On the dark side, some of the paragraphs can be so long that studying it, might become a drudgery. Moreover, there are no questions and answers, exercises or problems for the reader to solve. in order to reinforce learning.
All in all, this is the bible of the manager, full of information, but its formal structure resembles more of  a reference manual, not a course book to prepare for the exam.