Link to home
Start Free TrialLog in
Avatar of arthur_info
arthur_infoFlag for Brazil

asked on

How to filter the Apache messages in the console panel of Eclipse?

I want to show only errors and Warnings... Is there any way of to do this?

Thanks...
Avatar of Valeri
Valeri
Flag of Bulgaria image

It depends which Log implementation you are using. Log levels are ordered in this way :
trace, debug, info, warn, error, fatal
So for Log4J ypu should have
log4j.rootLogger = WARN, X
Avatar of arthur_info

ASKER

Well, I saw all the comments, but:
1. The link http://snippets.dzone.com/posts/show/3248 it's about a procedure very complex that, if I understood well, creates a file with a log.
2. The https://www.experts-exchange.com/questions/24828345/How-to-change-eclipse-log-level.html it's interesting, but what I really want it's to show in the console Window only what I want, not in the Error window. I'd attached a printscreen.

Thanks a lot!
Sem-t-tulo.jpg
As I can see your INFO messages are from Spring. Add this tag
<logger name="org.springframework">
        <level value="info"/>
    </logger>
to your log4j.properties file.
with value="warn" :-)
Well, I tried to follow the steps but two errors occurs in the console. I'm sending the log attached.

Error:

INFO: Initializing Log4J from [Y:\Desenvolvimento\Workfolder\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\sige-rh\WEB-INF\log4j.xml]
17/08/2010 14:02:35 org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener
java.lang.NoClassDefFoundError: org/apache/log4j/xml/DOMConfigurator
      at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:67)
      at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:151)
      at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:47)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
      at org.apache.catalina.core.StandardService.start(StandardService.java:516)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.xml.DOMConfigurator
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
      ... 18 more
17/08/2010 14:02:35 org.apache.catalina.core.ApplicationContext log
log.txt
My log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

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

  <appender name="console" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n"/>
    </layout>
  </appender>

  <root>
    <priority value ="error" />
    <appender-ref ref="console" />
  </root>

  <category name="org.springframework" additivity="false">
    <priority value="debug" />
    <appender-ref ref="console" />
  </category>
  
  <logger name="org.springframework">
     <level value="warn"></level>
     <level value="error"></level>
     <level value="fatal"></level>
     <level value="debug"></level>
     <level value="trace"></level>
  </logger>
  
</log4j:configuration>

Open in new window

I forget of to copy the library to lib folder. When I put in the lib folder, the following error appears:

log4j:ERROR Attempted to append to closed appender named [console].

Some idea?

Thanks!
Very strange?!
Since you have category tag you have to remove logger tag.
Probably console is used by other logger I changed it to cns.
try with this file :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

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

  <appender name="cns" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n"/>
    </layout>
  </appender>

  <root>
    <priority value ="error" />
    <appender-ref ref="cns" />
  </root>

  <category name="org.springframework" additivity="false">
    <priority value="warn" />
    <appender-ref ref="cns" />
  </category>
   
</log4j:configuration>
Well, now we have two new messages:

log4j:WARN Continuable parsing error 23 and column 23
log4j:WARN The content of element type "log4j:configuration" must match "(renderer*,throwableRenderer?,appender*,plugin*,(category|logger)*,root?,(categoryFactory|loggerFactory)?)".

The console is attached.

Thanks...
log.txt
Do you have commons-logging.jar in your Tomcat/lib folder? If you have remove it from there...
Hum, yes. I removed and some errors appeared... I' sending the console log attached.
log.txt
...and add it to your web application lib folder in order to read properties from your log4j.xml file instead of log4j.properties file placed in your tomcat/lib folder...
Well, I do what you tell me, but the error persists. So, I was searching in the web for another solution and founded an interesting configuration that, if I change my log4j.xml, more information go to the console. The problem is that I want only this messages and only if are messages of errors or warnings. I attached the files...
log4j.txt
The console file:
Console.txt
ok, that's good! Now in order to supress the messages you dont need, you have to add such categories:
for example, to supress messages from tomcat you have to add :
<category name="org.apache.tomcat" additivity="false">
    <priority value="error" />
    <appender-ref ref="CONSOLE" />
</category>
in order to stop messages from hibernate you have to add :
<category name="org.hibernate" additivity="false">
    <priority value="error" />
    <appender-ref ref="CONSOLE" />
</category>
In this way you can define different categories and different log levels for each one of them.
Also you can define different appender for System .err.
So, add this categories to your log4j.xml and try again.
Hum... There's something missing... I'm still with the console with a lot of INFO messages (in red) and some messages of log (in black). I'm not understanding one thing: the log4j.configuration is essential? Because I removed it thinking that the log4.xml it's sufficient to make the filter of log messages. In your article, there's a part that says:
"You can also choose to set the system property log4j.configuration before starting Tomcat. For Tomcat 3.x The TOMCAT_OPTS environment variable is used to set command line options. For Tomcat 4.0, set the CATALINA_OPTS environment variable instead of TOMCAT_OPTS."
How can I do that? I'm confuse, sorry.

log4j.txt
Console.txt
Log4j first is looking for log4j.xml, after that if there is no log4j.xml it is looking for log4j.properties file in order to configure itself. Yes, there is something missing?!?!?!
Which version of Tomcat you are using?
Probably your Log4J is not configured from your log4j.xml file?!
Take a look in your $CATALINA_HOME/lib folder. If there is log4j.properties file move it from there...
I'm using tomcat 6.0.20 and the log4j.properties doesn't exists in any apache folder. So, the problem is not this, I think.
wow :-( I was thinking that it's Tomcat 5.x
I saw that there are some issues with Tomcat 6 and xml based configuration files.
http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j
You have to use properties file. It's the same like xml configuration. I'll try to find some log4j.properties example that user ConsoleAppender.
Sorry once again that I didn't asked you for your Tomcat version earlier! Also I didn't know about this issues with Tomcat 6.
No problem. I was seeing this link but doesn't works. I created the file properties, I put in the conf folder, I put the log4j-1.2.16.jar in the lib folder, I didn't download any additional component, I didn't found the file output/extras/tomcat-juli.jar... Well, I'm lost... Do you know how to do this in a easy way?

Thanks a lot for your patience...
First of all I'd like to rollback last changes, so your Tomcat to be in the initial state, like the way before the question. Delete log4j.xml file and move commons-logging.jar back to $CATALINA_HOME/lib folder.
Also move log4j jar back to $CATALINA_HOME/lib folder.
Place the attached file in $CATALINA_HOME/lib, but before to place it rename it to "log4j.properties".
Now you can follow all of the steps from this link :
http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j
Extras components you can download from here:
http://apache.xenvps.us/tomcat/tomcat-6/v6.0.29/bin/extras/
log4j.txt
Hey!!! We're almost there!!!!!

The log now it's attached. The problem now it's that it's appearing only warn messages (I need the errors messages too) and some INFO messages from JSF it's appearing too, I need to filter this. How to fix that? Another problem I think it's that the logging.properties when I remove from the $CATALINA_HOME/conf folder the user doesn't log in my application. I think that I can't remove it... And now? What we can do?
0    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:vale-transporte' did not find a matching property.
3    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context/Realm} Setting property 'debug' to '99' did not find a matching property.
4    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:sige-lotacao' did not find a matching property.
4    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:sige-rh' did not find a matching property.
4    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context/Realm} Setting property 'debug' to '99' did not find a matching property.
5    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Concurso' did not find a matching property.
5    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context/Realm} Setting property 'debug' to '99' did not find a matching property.
20/08/2010 09:31:05 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_05-b06-FCS) for context '/Concurso'
20/08/2010 09:31:18 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_05-b06-FCS) for context '/sige-rh'
20/08/2010 09:31:19 com.sun.faces.config.processor.NavigationConfigProcessor addNavigationCasesForRule
AVISO: JSF1058: The resource referred to by to-view-id, 'cadastro/funcionario.jsp', for navigation from '*', does not start with '/'.  This will be added for you, but it should be corrected.
20/08/2010 09:31:19 com.sun.faces.config.processor.NavigationConfigProcessor addNavigationCasesForRule
AVISO: JSF1058: The resource referred to by to-view-id, 'cadastro/carencia.jsp', for navigation from '*', does not start with '/'.  This will be added for you, but it should be corrected.
20/08/2010 09:31:20 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_05-b06-FCS) for context '/vale-transporte'
20/08/2010 09:31:22 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_05-b06-FCS) for context '/sige-lotacao'

Open in new window

Hey, forget about what I said about logging.properties. There's no problem when I remove it.  :)
>> The problem now it's that it's appearing only warn messages (I need the errors messages too)
You don't have error msgs, that's way there are no errors in your log. In this log4j.properties file you have defined WARN log level, it means that only WARN, ERROR & FATAL will be displayed.
>> and some INFO messages from JSF it's appearing too
In order to stop these messages(from JSF) you have to open your log4j.properties file and to add this line at the end :
log4j.logger.com.sun.faces=WARN
it will stop all messages from package "com.sun.faces" with log level < WARN.
In this way you can configure whatever you want for your packages. You can set WARN for some of them, DEBUG for some others...
Hum... Ok...
Well, I'd changed the log4j.properties but the Info messages keep appearing... I'd stopped and start again apache but nothing... Weird... What can be?
# ***** Set root logger level to WARN and its only appender to A.
log4j.rootLogger=WARN, A

# ***** A is set to be a ConsoleAppender.
log4j.appender.A=org.apache.log4j.ConsoleAppender
# ***** A uses PatternLayout.
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n


log4j.logger.org.apache.catalina=WARN
log4j.logger.org.hibernate.cfg=WARN
log4j.logger.com.sun.faces=WARN

Open in new window

Add also this line to your log4j properties file :
log4j.logger.com.sun.faces.config.ConfigureListener=WARN
Hope it will help you.
Logging in such as frameworks (like jsf) is more specific from time to time.
http://java.sun.com/javaee/javaserverfaces/docs/README
see "Logging support and configuration steps" section.
Ops! There's something wrong here. I removed the log4j.properties and the console log became equals to the attached file 1. When I just put it again, the console backs to the attached file 2. When I remove the lines below from the log4j.properties, nothing changes.

log4j.logger.org.apache.catalina=WARN
log4j.logger.org.hibernate.cfg=WARN
log4j.logger.com.sun.faces=WARN
log4j.logger.com.sun.faces.config.ConfigureListener=WARN

I'm thinking that the log4j.properties is filtering some messages, but when the messages cames from JSF, the messages comes from another way that the filter doesn't works. Some idea?

Thanks a lot again...
Console1.txt
Attached file 2:
Console2.txt
Yes, there is something wrong!!! :-(
First of all, let's check for possible mistakes.
1. log4j.properties should be in your WEB-INF/classes folder, it means you have to keep it in src folder and after building of the application to go to
WEB-INF/classes?
2. Check that there is no commons-logging.properties file presented in your WEB-INF/classes folder.
3. Check that commons-logging jar is not presented in your lib folder.
After cheking this try again.

If you still got the messages from jsf you can try another solution.
Probably JSF uses only the standart Logger to log msgs. I don't know that, I've never logged jsf msgs, but in order to workaround this you can set explicitly the right logger.
Create your own commons-logging.properties file and add this line:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
In this way Log4JLogger will be used.

>>When I remove the lines below from the log4j.properties, nothing changes.
log4j.logger.org.apache.catalina=WARN
log4j.logger.org.hibernate.cfg=WARN
log4j.logger.com.sun.faces=WARN
log4j.logger.com.sun.faces.config.ConfigureListener=WARN

Yes, this is because the log level of the root logger - WARN is the same like log level of the loggers in this lines.
P.S. For the second solution you need to put back your commons-logging jar file in your lib folder.
Hope it will help you!
Oh man, I'm sorry. But is not working yet... Let's check the steps again:
About the 1 step: My log4j.properties it's only in the $CATALINA_HOME/lib folder, not in the folders of my projects. Do I need to put in another folder?
2: In the $CATALINA_HOME/conf folder there is only the file logging.properties.bak (the old logging.properties file). I renamed to commons-logging.properties and added the line "org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger" but doesn't works (I'm sending attached).
3. No, it's only in the "conf" folder.

Well... It's only this... Sorry for take your time...

commons-logging.properties.txt
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey... Very interesting... See how my console is showing now... Well... Now, if I'm understanding, I will see only errors and warnings at all, ok? Left only one message "INFO", but I think that it's not a problem... Don't you think? Can I close this topic? Can I thank you very much???   :)
Console.jpg
>> Left only one message "INFO", but I think that it's not a problem...
As I can see this INFO msg is from context logger, so adding this line
javax.enterprise.resource.webcontainer.jsf.context.level=WARNING
to your logging.properties file should remove it.
Here are all lines that concerns JSF logging :

javax.enterprise.resource.webcontainer.jsf.application.level=INFO
javax.enterprise.resource.webcontainer.jsf.resource.level=INFO
javax.enterprise.resource.webcontainer.jsf.config.level=INFO
javax.enterprise.resource.webcontainer.jsf.context.level=INFO
javax.enterprise.resource.webcontainer.jsf.facelets.level=INFO
javax.enterprise.resource.webcontainer.jsf.lifecycle.level=INFO
javax.enterprise.resource.webcontainer.jsf.managedbean.level=INFO
javax.enterprise.resource.webcontainer.jsf.renderkit.level=INFO
javax.enterprise.resource.webcontainer.jsf.taglib.level=INFO
javax.enterprise.resource.webcontainer.jsf.timing.level=INFO

I have added only some of them, that's way this INFO msg was left!
So add the line manually, next to the lines that concerns jsf logging (in logging.preoperties file) and the msg sould disappear.
I didn't know that Sun's implementation of jsf uses standard jdk logging. Now I know it! :-)
That's way spring, hibernate and all of the other msgs, logged from log4j have to be controlled from log4j.properties file. The msgs logged from the standard jdk logger have to be contrlled from logging.properties file.
Keep in mind that log level set for log4j.rootLogger is valid for all of the other loggers not set explicitly.
>> Now, if I'm understanding, I will see only errors and warnings at all, ok?
Yes
I have to thank you! :-) because I learned new things about tomcat 6 logging...
hehehe... You're a very smart person...  :)

Well... I want to tell you that it's all right, but the line that you want that I put in the logging.properties already has in that file. I'm sending the file attached (with .txt extension). There is another thing missing here... Don't you think?
logging.properties.txt
Hmmmm...?! :-) What is missing?!
This line was not presented in the first version of the file?!
Yes... But the console is showing the INFO message yet, like the Comment ID: 33543739.
What I'm trying to say is that when you said:

"As I can see this INFO msg is from context logger, so adding this line
javax.enterprise.resource.webcontainer.jsf.context.level=WARNING
to your logging.properties file should remove it."

The line "javax.enterprise.resource.webcontainer.jsf.context.level=WARNING" was already in the logging.properties.

Understand?
Hmmm... Very strange! :-(
Probably this msg comes from a logger which is not in the list in logging.properties file.
I saw that the base jsf logger is defined in this way :
javax.enterprise.resource.webcontainer.jsf
so try with adding this line to logging.properties file:
javax.enterprise.resource.webcontainer.jsf.level=WARNING
but I'm not sure about that, it's just a suggestion...
Hum... Don't works... I'm still seeing this messages attached... But, if this is a problem, don't worry... I can close this topic... Hey, is permitted to send e-mails here? I wanna ask one thing to you. If yes, mine is arthur_info yahoo com br.

Thanks for all...


0    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:vale-transporte' did not find a matching property.
3    [main] WARN  org.apache.commons.digester.Digester  - [SetPropertiesRule]{Server/Service/Engine/Host/Context/Realm} Setting property 'debug' to '99' did not find a matching property.
31/08/2010 14:45:03 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_05-b06-FCS) for context '/vale-transporte'

Open in new window

Very strange! I googled for this and I found the code of this class. See :
http://grepcode.com/file/repository.jboss.com/maven2/javax.faces/jsf-impl/1.2_04-p02/com/sun/faces/config/ConfigureListener.java
the logger is instantiated in the right way, so this msg is not from this logger. May be from the global logger, I don't know?!
I thing that it's a kind of oversight and the developers from Sun will fix this in the next release?!
>> Hey, is permitted to send e-mails here?
I don't know. Why not?! I've seen that other guys have emails in their profiles...
my is v__i__k hotmail com
No problem Valeri. I'll close this topic ok? Thanks a lot by everything.