File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes logs of different package to be written to different logs 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 "logs of different package to be written to different logs " Watch "logs of different package to be written to different logs " New topic

logs of different package to be written to different logs

venkat bagavathi subramanian

Joined: Dec 21, 2003
Posts: 19
Basically i have 2 packages and i want the info logs from each of them to be written to a separate log file. Currently all info logs from both the packages go into a common log file(Integration.log). is it possible to specify that info logs from a package should go to one appender and those from the other package should go to another? if so how.
Below is the Log4j.prperties contents.
Pl help me how to achieve this.
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit;}\viewkind4\uc1\pard\f0\fs20 # Attach appender A1 to root. Set root level to Level.DEBUG.\par
log4j.rootLogger=DEBUG,A1, A2\par
# A1 is set to be a FileAppender sending its output to\par
# System.out. However, only error messages and above will be printed\par
# in A1 because A1's threshold is set to Level.ERROR.\par
# The fact that the root level is set to Prority.DEBUG only influences\par
# log requests made to the root logger. It has no influence on the\par
# *appenders* attached to root.\par
log4j.appender.A1.layout.ConversionPattern=%p [%t] %c\{2\} (%M:%L) - %m%n\par
# Set the level of the logger named "org.apache.log4j.examples" to\par
# Level.INFO, attach appender A2.\par, A2\par
# Appender A2 writes to the file "test" in user's home.\par
# log4j.appender.A2=org.apache.log4j.RollingFileAppender\par
# log4j.appender.A2.File=d:/Integration/log/Test.log\par
# Truncate 'test' if it aleady exists.\par
# Appender A2 uses the PatternLayout.\par
log4j.appender.A2.layout.ConversionPattern=[%d\{ISO8601\}] %-5p %c\{2\}.%M: %m%n\par

[ May 12, 2006: Message edited by: venkat bagavathi subramanian ]
[ May 13, 2006: Message edited by: venkat bagavathi subramanian ]
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Define the level and appender for the packages' loggers (and define those appenders, not shown):,A3,A4

You may need to set the additivity flag if you don't want the messages in parent logs.
# Additivity set to false will not log the rootLogger (avoid dup messages
# when specifying the same ones)
I agree. Here's the link:
subject: logs of different package to be written to different logs
It's not a secret anymore!