• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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
  • 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: 3281
8
Mac OS X Eclipse IDE Java
  • 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!
 
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
 
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 ]
 
Skool. Stay in. Smartness. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!