log4j and jsf

I added log4j in my application. It is working and I can see my log.debug statements in the console. The problem is that I can see more than I want. My application uses jsf and Tomcat and I see many jsf debugs and I do not know what to change in my log4j.properties so as not to view them. My log4j.properties is the following:

log4j.rootLogger=debugLog, stdout

# CONSOLE appender

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %-5p %m%n

log4j.appender.debugLog=org.apache.log4j.DailyRollingFileAppender

log4j.appender.debugLog.Threshold=debug

log4j.appender.debugLog.layout=org.apache.log4j.PatternLayout

log4j.category.com.corejsf = debugLog

I tried to add something like the following

log4j.category.com.sun.faces = WARN

log4j.additivity.com.sun.faces=false

but nothing changed.Any suggestions?

[1095 byte] By [juanitaJa] at [2007-11-26 15:21:13]
# 1

Hi

Try doing this

Create a file named log4j.properties & put the below content into it

log4j.rootLogger=DEBUG, R

log4j.appender.R=org.apache.log4j.RollingFileAppender

log4j.appender.R.File=${catalina.home}/logs/MyLog.log

log4j.appender.R.MaxFileSize=10MB

log4j.appender.R.MaxBackupIndex=10

log4j.appender.R.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=[%d] %p %t %c - %m%n

now put this file in \jakarta-tomcat-5.0.28\common\classes

This will control the logging of ur application. Now u won't see any log messages in ur console instead it will be logged in MyLog.log in logs directory inder tomcat.

Hope this works 4 u

Regards

Amit

Amit.Naira at 2007-7-8 11:50:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I did what you suggested but now nothing is debugged. I want to remove extra jsf debug but I want to be able to view my log.debug that I insert in my code.
juanitaJa at 2007-7-8 11:50:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Sun RI uses the jdk logging api, not log4j
amitteva at 2007-7-8 11:50:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
So what should I do?I have to use another jar ?You mean that jsf cannot work with log4j?
juanitaJa at 2007-7-8 11:50:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi,

It depends on which version of RI. Prior to 1.2, jsf-RI uses apache's commons-logging.

In case you're using RI 1.1:

1. you can add a log4-1.2.9.jar and a commons-logging.jar in the WEB-INF/lib directory

2. Add a log4j.properties in the WEB-INF/classes containing what has been described in previous posts of this thread.

trevorijonesa at 2007-7-8 11:50:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
I am using jsf 1.1 , log4j-1.2.8 and commons-logging-1.0.3.jarIs it necessary to have log4j-1.2.9?
juanitaJa at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
I tried also with the log4j-1.2.9My problem is that I get the debugs but I get two many debugs that come from the jsp components so I am asking If I can add anything in the log4j.properties so as to exclude the jsf debugs
juanitaJa at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Well, i always use this:

log4j.logger.org.apache=INFO

log4j.logger.org.hibernate=DEBUG

//log4j.logger.net.sf=DEBUG

// no more debug from faces

//log4j.logger.javax.faces=DEBUG

log4j.logger.net.pimpas=DEBUG

CasMeirona at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Nothing is working .Here is a sample of the many debugs.

17:40:19 DEBUG addRenderer(javax.faces.Input,javax.faces.Textarea,com.sun.faces.renderkit.html_basic.TextareaRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Messages,javax.faces.Messages,com.sun.faces.renderkit.html_basic.MessagesRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Message,javax.faces.Message,com.sun.faces.renderkit.html_basic.MessageRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Output,javax.faces.Format,com.sun.faces.renderkit.html_basic.OutputMessageRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Output,javax.faces.Label,com.sun.faces.renderkit.html_basic.LabelRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Output,javax.faces.Link,com.sun.faces.renderkit.html_basic.LinkRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Output,javax.faces.Text,com.sun.faces.renderkit.html_basic.TextRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Panel,javax.faces.Grid,com.sun.faces.renderkit.html_basic.GridRenderer)

17:40:19 DEBUG addRenderer(javax.faces.Panel,javax.faces.Group,com.sun.faces.renderkit.html_basic.GroupRenderer)

17:40:19 DEBUG addRenderer(javax.faces.SelectBoolean,javax.faces.Checkbox,com.sun.faces.renderkit.html_basic.CheckboxRenderer)

17:40:19 DEBUG addRenderer(javax.faces.SelectMany,javax.faces.Checkbox,com.sun.faces.renderkit.html_basic.SelectManyCheckboxListRenderer)

17:40:19 DEBUG addRenderer(javax.faces.SelectMany,javax.faces.Listbox,com.sun.faces.renderkit.html_basic.ListboxRenderer)

17:40:19 DEBUG addRenderer(javax.faces.SelectMany,javax.faces.Menu,com.sun.faces.renderkit.html_basic.MenuRenderer)

17:40:19 DEBUG addRenderer(javax.faces.SelectOne,javax.faces.Listbox,com.sun.faces.renderkit.html_basic.ListboxRenderer)

17:40:19 DEBUG addRenderer(javax.faces.SelectOne,javax.faces.Menu,com.sun.faces.renderkit.html_basic.MenuRenderer)

17:40:19 DEBUG addRenderer(javax.faces.SelectOne,javax.faces.Radio,com.sun.faces.renderkit.html_basic.RadioRenderer)

17:40:19 DEBUG addValidator(javax.faces.DoubleRange,javax.faces.validator.DoubleRangeValidator)

juanitaJa at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

This is a log4j properties file problem. I'm not used to using the .properties file notation. I'm used to the XML notation for log4j.

Here's how I'd do it in XML:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

<!--

Set up the appender

-->

<appender name="Appender" class="org.apache.log4j.ConsoleAppender">

<param name="Append" value="true"/>

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d{HH:mm:ss} %-5p %m%n"/>

</layout>

</appender>

<logger name="my.java.package" additivity="false">

<level value="debug" />

<appender-ref ref="Appender" />

</logger>

<logger name="another.package.for.debug.level" additivity="false">

<level value="debug" />

<appender-ref ref="Appender" />

</logger>

<!--

Omitting the JSF package altogether should remove the undesired

DEBUG messages from it. However, if not, uncomment the following

lines.

-->

<!-- <logger name="javax.faces" additivity="false">

<level value="INFO" />

<appender-ref ref="Appender" />

</logger> -->

<root>

<priority value ="debug" />

<appender-ref ref="Appender" />

</root>

</log4j:configuration>

This example will print to console only. If you want to print to a file instead, use the following lines (replaces the appender tags from the above example).

<appender name="Appender" class="org.apache.log4j.DailyRollingFileAppender">

<param name="File" value="filePath/FileName.log"/>

<param name="DatePattern" value="'.'yyy-MM-dd"/>

<param name="Append" value="true"/>

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d{HH:mm:ss} %-5p %m%n"/>

</layout>

</appender>

I don't know how you'd get both the console and the file appender working at the same time.

If you want further advice, or If you want advice on the .properties method of doing things, I suggest finding a log4j forum. The people there will undoubtedly have more experience and knowledge than us JSF nerds. =)

I assure you though, JSF is compatible with log4j. The log4j properties file just needs to be set up properly (more challenging than it should be, if you ask me).

CowKing

IamCowKinga at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

Now that you have:

1. a log4j.jar (1.2.8 or 1.2.9) in WEB-INF/lib

2. a commons-logging.jar in WEB-INF/lib

3. add a log4j.properties in WEB-INF/classes:

log4j.rootLogger=ERROR, stdout

### Console display ###

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p - %c - %m%n

### Enabling debug logging for jsf-ri implementation of Lifecycle only ###

log4j.logger.com.sun.faces.lifecycle.LifecycleImpl=DEBUG

You'll have only debug info for this particular class in the catalina.out (if you're using tomcat)

trevorijonesa at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

I tried all your suggestions again I have debugs that I don't need.

My log4j.properties is:

log4j.rootLogger=debugLog, stdout

# CONSOLE appender

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %-5p %m%n

log4j.appender.debugLog=org.apache.log4j.DailyRollingFileAppender

log4j.appender.debugLog.Threshold=debug

log4j.appender.debugLog.layout=org.apache.log4j.PatternLayout

log4j.category.com.corejsf = debugLog

log4j.category.org.apache.commons=ERROR

log4j.category.org.apache.struts=ERROR

### Enabling debug logging for jsf-ri implementation of Lifecycle only ###

log4j.logger.com.sun.faces.lifecycle.LifecycleImpl=DEBUG

log4j.com.sun.faces=ERROR

Still I have too many debugs such as:

10:38:10 DEBUG addConverterByClass(float,javax.faces.convert.FloatConverter)

10:38:10 DEBUG added converter of class type javax.faces.convert.FloatConverter

10:38:10 DEBUG addConverterByClass(int,javax.faces.convert.IntegerConverter)

10:38:10 DEBUG added converter of class type javax.faces.convert.IntegerConverter

10:38:10 DEBUG addConverterByClass(long,javax.faces.convert.LongConverter)

10:38:10 DEBUG added converter of class type javax.faces.convert.LongConverter

10:38:10 DEBUG addConverterByClass(short,javax.faces.convert.ShortConverter)

juanitaJa at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13

Hi,

You have mixed your log4j.properties and the one i suggested

try exactly this one:

log4j.rootLogger=ERROR, stdout

### Console display ###

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p - %c - %m%n

### Enabling debug logging for jsf-ri implementation of Lifecycle only ###

log4j.logger.com.sun.faces.lifecycle.LifecycleImpl=DEBUG

Then you should have only debug logging for LifecycleImpl.

trevorijonesa at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14

JuanitaJ:

I had the same problem as you, but finally figured it out!

the problem is that you (and I) define a rootLogger in the log4j.properties file.

This is the parent of all other loggers including loggers defined in the JSF components.

Instead of declaring:

log4j.rootLogger=DEBUG, destConsole, destFile

I now declare an app-specific logger to be the parent of all loggers I use in my project:

log4j.logger.jsf_db=DEBUG, destConsole, destFile

In java I set up my logger as a child of this logger:

import org.apache.log4j.Logger;

..

..

private Logger logger = Logger.getLogger("jsf_db." + this.getClass());

my complete lo4j properties file is:

#log4j.rootLogger=DEBUG, destConsole, destFile

log4j.logger.jsf_db=DEBUG, destConsole, destFile

log4j.appender.destConsole=org.apache.log4j.ConsoleAppender

log4j.appender.destConsole.layout=org.apache.log4j.PatternLayout

log4j.appender.destConsole.layout.ConversionPattern=%d %-5p %-5c{3}:%L %x -> %m%n

log4j.appender.destFile=org.apache.log4j.RollingFileAppender

log4j.appender.destFile.MaxFileSize=2500KB

#log4j.appender.destFile.File=D:\\data\\projects\\JSF\\jsf_db\\webRoot\\log\\jsf_db.log

log4j.appender.destFile.File=/data/projects/jsf_db/webRoot/log/jsf_db.log

log4j.appender.destFile.layout=org.apache.log4j.PatternLayout

log4j.appender.destFile.layout.ConversionPattern=%d %-5p %-5c{3}:%L %x -> %m%n

TheRealLocutusa at 2007-7-8 11:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15

I tried your solution but it didn't work I could not see any log.debug.

What exactly is jsf_db?An existing package ?Or sth you have created?

Before I see your answer I managed to solve my problem

it by setting

:# Set additivity to false, so not to inherit from the parent

log4j.additivity.com.corejsf=false

com.corejsf is the package where I have my java files.

#To reduce hibernate extra logging

log4j.logger.org.hibernate=errorLog

juanitaJa at 2007-7-21 16:24:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16

But I thought to inherit from the parent made log4j so interesting,

now you cannot change the log-level system-wide with

just 1 change in the log4j properties file.

Now you have to set the level of every logger you create in your code.

At the risk of being boring I will explain what I did:

"jsf_db" is just a name, it happens to be the name of my application,

but you can just as well choose: "any_root_name_you_like".

so you can declare in the properties file:

log4j.logger.any_root_name_you_like=DEBUG, appender1 appender2

In my application I have many classes, in every class I define:

private Logger logger = Logger.getLogger("any_root_name_you_like." + this.getClass());

which gives me a loggernamed "any_root_name_you_like.className"

which is a child of "any_root_name_you_like" and thus inherits it's level from it.

Now I still can change my applications logtlevel with 1 change in the properties file.

By the way, using this.class() tells me directly where the logged event ocurred.

TheRealLocutusa at 2007-7-21 16:24:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...