1

I have this log4j.properties:

# Global logging configuration
log4j.rootLogger=WARN, file

### Direct log messages to a log file
log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File= C:\\eclipse\\servers\\apache-tomcat-6.0.39\\logs\\log4j.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n


### Console messages Appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout  
log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n

### Appender-to-Class definition
log4j.logger.com.XXX.payplatform.test.*=INFO, console
log4j.additivity.com.XXX.payplatform.test.*=false

So, ok, the WARN level information is being registered in the log4j.log file. That's OK.

But, I want to see INFO-level messages in my eclipse console, but i am not getting any response there.

Any solutions? I think the problem is in the "WARN, file" rootLogger configuration, so i tried this:

# Global logging configuration
log4j.rootLogger=INFO, file

But no changes resulted...

Thank you!

George Fandango
  • 121
  • 1
  • 12

1 Answers1

0

Read more Apache log4j 1.2 - Short introduction to log4j and find the samples as well.

Level Inheritance

The inherited level for a given logger C, is equal to the first non-null level in the logger hierarchy, starting at C and proceeding upwards in the hierarchy towards the root logger.

Basic Selection Rule

A log request of level p in a logger with (either assigned or inherited, whichever is appropriate) level q, is enabled if p >= q.

This rule is at the heart of log4j. It assumes that levels are ordered. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL.


It should be like this. Add console here and set default root log level to INFO.

log4j.rootLogger=INFO, file, console

OR

Try with log4j.xml instead of log4j.properties. Read more Configuring Log4j 2

Sample 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="STDOUT" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601} %5p %c{1}:%L - %m%n" />
        </layout>
    </appender>

    <appender name="FILE_LOG" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="/logs/log4j.log" />
        <param name="Append" value="true" />
        <param name="ImmediateFlush" value="true"/>
        <param name="DatePattern" value="'.'dd-MM-yyyy-HH"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601} %5p %c{1}:%L - %m%n" />
        </layout>
    </appender> 
        
    <category name="com.XXX.payplatform.test">
        <priority value="INFO" />
        <appender-ref ref="STDOUT"/>
    </category> 
    
    <root> 
        <priority value ="ERROR" />
        <appender-ref ref="FILE_LOG" />
    </root>
</log4j:configuration>
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • THANKS!!! But... What happends if I want to just only collect WARN (or greater) messages in the rootLogger BUT I want to see every DEBUG (or greater) messages in my console? EDIT: I'm getting the same output both file and console, the com.XXX.foo.bar class output as well. – George Fandango Jun 03 '14 at 12:33
  • you can try with `log4j.xml` where you have full control on it. Find it here [Log4j - priority value and param name concept explanation](http://stackoverflow.com/questions/8653548/log4j-priority-value-and-param-name-concept-explanation) – Braj Jun 03 '14 at 12:35
  • Thank you Braj, but I can't do that due to company's restrictions :( must be log4j.properties file – George Fandango Jun 03 '14 at 12:37
  • [Log4j is an open source project](http://logging.apache.org/log4j/1.2/manual.html) – Braj Jun 03 '14 at 12:39
  • Yeah, reading the documentation at the same time... Just getting the same output in file and console... PD: Thank you! – George Fandango Jun 03 '14 at 12:41
  • Find the solution [here](http://stackoverflow.com/questions/1725958/how-do-you-change-a-packages-log-level-using-log4j) using log4j.properties. – Braj Jun 03 '14 at 12:46
  • 1
    Hi there Braj, I found a solution looking at the links you gave me. I post it and give you credit! Thank you very much!!! – George Fandango Jun 03 '14 at 13:42
  • I'm having some troubles, seems like the solution is not so perfect. Keep searching! – George Fandango Jun 03 '14 at 14:09
  • Allright, finished. I will post the solution. Thank you soooo much! – George Fandango Jun 03 '14 at 14:15
  • Due to reputation, I can't post it till tomorrow... see ya later! – George Fandango Jun 03 '14 at 14:27