Friday, October 23, 2009

Adding Log4j Logging to a Portlet

System.out is used to put one feel that it give any Performance performance. Now change to try and see Log4j may helpSet out how to write well.

1. First, they need to download log4j before

here http://logging.apache.org/log4j/1.2/download.html.

2. When we have already loaded the file will be much different to many files for extension. Jar.

It is outmostEg. Zip to extract the directory name apache-log4j-1.2.15. c: / apache-log4j-1.2.15/log4j-1.2.15.jar.

3. File log4j-1.2.15.jar. That has to be placed in the path / WEB-INF/lib of Portlet.

4. And then create the file. log4j.properties. By creating this file under this directory. JavaResources / JavaSource.

5. Then change the file. log4j.properties example.

# An example log4j configuration file.

log4j.rootLogger = DEBUG, FILE.

log4j.appender.FILE = org.apache.log4j.FileAppender.

log4j.appender.FILE.File = C: / log / SSOApplicationPortlet.log.

log4j.appender.FILE.Append = true.

log4j.appender.FILE.layout = org.apache.log4j.PatternLayout. log4j.appender.FILE.layout.ConversionPattern = [%-d (yyyy-MM-dd HH: mm: ss)] [% 37c]% 3x -% m% n. Details would be used more.

To write here. http://logging.apache.org/log4j/1.2/manual.html.

6. To see our Portlet When we use Log4j finished we will come running to see.

7. In Class we want to keep or Debug Log Import this into us.

import org.apache.log4j.Logger;

Global variables and then announced to run the following log.

private static Logger logger = Logger.getLogger (name ClassPortlet.class);

And it comes out out outttttt log of each visit Log want to keep this where to use. System.out.println ( "Start doView ()"); / / not used bylogger.debug ( "Start doView ()"); / / Use this to remove.

8.'re Done use Log4j to see if the output is to see the path that we write Set in log4j.properties.