Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anutosh Swamy
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Vilpesh Mistry
Ranch Hand
Posts: 62
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic