• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 62
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic