File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Log4j - How to direct log messages to their respective log message file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Log4j - How to direct log messages to their respective log message file" Watch "Log4j - How to direct log messages to their respective log message file" New topic
Author

Log4j - How to direct log messages to their respective log message file

Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Hi,

Can any one help me with directing the log messages in Log4j to their respective logger files.

For example:

I need to direct the INFO level messages to info-logger.log file
WARN level message to warn-logger.log file
ERROR level message to error-logger.log file and so on

and no file will have the messages from different level loggers, means info-logger.log file will have INFO level messages only and not the WARN or ERROR level messages and so on.

NOTE:: I am using only log4j.properties configuration file and not the log4j.xml

Thanks in advance

K.Anutosh
----------------------------------------------------------------
SCJP 1.4
SCWCD 1.4
OCA (Paper I)


K. Anutosh<br /> <br />SCJP 1.4<br />SCWCD 1.4<br />OCA (Paper I)
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

IIRC (and I haven't done this recently), I think you can by using a LevelMatchFilter, see this section of the FAQ for further help.

Let us know how you get on, I'm curious about this myself!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Vilpesh Mistry
Ranch Hand

Joined: May 27, 2003
Posts: 62
In log4j appenders represent the channel where you can send the information to be logged.
Write a Java program to pass different appender name to following log4j api call ----
Log logr = null;
logr = Logger.getLogger(--appender name--);
logr.debug("Entering Javaranch");

passing different appender name is like asking Log4j to write in different log files.
your application has to pick up correct appender name and pass it to logger so that information is written in different log files.

thanks
Vilpesh


Thanks.
Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
But how can I achieve it that I don't have to ask for a specific appender? I just want to say



without having to worry about the appenders but still having



writing to debug.log and



writing to info.log?

I tried the following:


But info and debug messages are still in both files. Log4J version is 1.2.15. What am I missing here?
[ November 23, 2008: Message edited by: Mike Himstead ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4j - How to direct log messages to their respective log message file