log4j and console in ANT/JUnit task

B

BlueDolphin

Seems log4j is playing some magic...

It always try to write debug info to console. If I set the rootLogger
to INFO, then no info on both console and log file, if I set to DEBUG,
message goes to both console and log....

Confusing....
I tried RollingFileAppender too....

Thanks

I have the following log4j.properties
log4j.rootLogger = DEBUG, RRX

#log4j.rootLogger = OFF, stdout

log4j.appender.RRX=org.apache.log4j.FileAppender
log4j.appender.RRX.File=MyRRX.log
log4j.appender.RRX.layout=org.apache.log4j.PatternLayout
log4j.appender.RRX.layout.ConversionPattern=%d %-5p %c - %m%n
#log4j.appender.RRX.append=false
 
O

Oscar kind

BlueDolphin said:
Seems log4j is playing some magic...

It always try to write debug info to console. If I set the rootLogger
to INFO, then no info on both console and log file, if I set to DEBUG,
message goes to both console and log....

No magic: you tell the logger to log something or not.

What you want is to tell the appenders to disregard some of what the
loggers log. An appender has a threshold as well.

This is all documented BTW.
 
J

jacksu

Oscar kind said:
No magic: you tell the logger to log something or not.

What you want is to tell the appenders to disregard some of what the
loggers log. An appender has a threshold as well.

This is all documented BTW.

The point is, I am using FileAppender, which is suppose to only write
to file, which it did, but no point for FileAppender to write to
console at the same time, it is ConsoleAppender's job.....
 
O

Oscar kind

jacksu said:
The point is, I am using FileAppender, which is suppose to only write
to file, which it did, but no point for FileAppender to write to
console at the same time, it is ConsoleAppender's job.....

My mistake, I thought it was just about the log levels.

The same documentation is still very helpful: it states that you can use
more than one appender for a logger. You specify all appenders and the
threshold of the logger in the logger's definition, and the specific
threshold with the appender:

--- begin partial log4j configuration ---
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Threshold=WARN
# Some more properties...

log4j.appender.Application=org.apache.log4j.RollingFileAppender
log4j.appender.Application.Threshold=DEBUG
# Some more properties...

log4j.rootLogger=INFO, Console, Application
---- end partial log4j configuration ----

Here, "info" and worse is logged to a file (even though the appender also
writes for "debug"). Warnings and worse are also logged to the console.
 
B

BlueDolphin

Oscar kind said:
My mistake, I thought it was just about the log levels.

The same documentation is still very helpful: it states that you can use
more than one appender for a logger. You specify all appenders and the
threshold of the logger in the logger's definition, and the specific
threshold with the appender:

--- begin partial log4j configuration ---
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Threshold=WARN
# Some more properties...

log4j.appender.Application=org.apache.log4j.RollingFileAppender
log4j.appender.Application.Threshold=DEBUG
# Some more properties...

log4j.rootLogger=INFO, Console, Application
---- end partial log4j configuration ----

Here, "info" and worse is logged to a file (even though the appender also
writes for "debug"). Warnings and worse are also logged to the console.

THanks for the information. I set the Threshold like you suggested,
but I am still seeing the message printed to the console.

BTW, I am using ANT's JUnit task to run my program, does that affected
something?

Thanks a lot.
 
O

Oscar kind

BlueDolphin said:
BTW, I am using ANT's JUnit task to run my program, does that affected
something?

No, but yes. You still need to make sure the loj4j configuration file is
loaded. So in this regard nothing changes.

But, the way the log4j configuration file is loaded now may differ from
the way you usually do this. So it is something to verify again.
 
B

BlueDolphin

Oscar kind said:
No, but yes. You still need to make sure the loj4j configuration file is
loaded. So in this regard nothing changes.

But, the way the log4j configuration file is loaded now may differ from
the way you usually do this. So it is something to verify again.

Sure, I believe the log4j in ant is different, but how to work on it
properly?

It reads the root.logger settings from the logger.properties. Seems
just have one default consoleappender, silently associate with the
root.logger's setting...

Any idea to split the relation?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top