aspose file tools
The moose likes Java in General and the fly likes How to log statements using log4j in file and console with different log levels? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to log statements using log4j in file and console with different log levels?" Watch "How to log statements using log4j in file and console with different log levels?" New topic
Author

How to log statements using log4j in file and console with different log levels?

Vaman Kulkarni
Greenhorn

Joined: Nov 06, 2009
Posts: 6
Hi all,

I am using log4j for logging in my application. My requirement is to log DEBUG statements in a log file and INFO statements in console.
Here is my sample log4j.properties.



In above file, I set rootLogger to log DEBUG statements in a fileAppender and another logger "com.ptc.v1tool" to log INFO statements in console.
But the log file contains same entries as that in console i.e. log file contains only INFO logs

Can anyone suggest me how to accomplish my requirement?

Thanks.
Kim Boone
Greenhorn

Joined: Oct 22, 2009
Posts: 3
Varun,

I would suggest using an log4j.xml file. There is an excellent tutorial on logging at http://www.laliluna.de/log4j-tutorial.html. This tutorial will walk you thru all of the steps.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32712
    
    4
Welcome to JavaRanch

We prefer to keep this "beginning" forum for really easy questions, so I shall move you where the more difficult questions live.
Vaman Kulkarni
Greenhorn

Joined: Nov 06, 2009
Posts: 6
Thanks Kim for your input. Proved very useful for me.

Thanks Ritchie..I would keep that in mind next time before posting.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to log statements using log4j in file and console with different log levels?
 
Similar Threads
Logger don't write info and debug in Log file
Logging SQL statements
Log4j : specific class to log on FileAppender other classes log on Console Appender.
How can i add Log4j suppourt to my Application
Need help with log4j logging tool to log into database