This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

logs of different package to be written to different logs

venkat bagavathi subramanian
Greenhorn

Joined: Dec 21, 2003
Posts: 19
hi,
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.
regards
venkatB
-----------------------------------------------------------------------
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 # Attach appender A1 to root. Set root level to Level.DEBUG.\par
log4j.rootLogger=DEBUG,A1, A2\par
\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
\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
\par
log4j.appender.A1=org.apache.log4j.ConsoleAppender\par
log4j.appender.A1.Threshold=ERROR\par
\par
log4j.appender.A1.layout=org.apache.log4j.PatternLayout\par
log4j.appender.A1.layout.ConversionPattern=%p [%t] %c\{2\} (%M:%L) - %m%n\par
\par
# Set the level of the logger named "org.apache.log4j.examples" to\par
# Level.INFO, attach appender A2.\par
#log4j.logger.org.apache.log4j.examples=INFO, A2\par
\par
# Appender A2 writes to the file "test" in user's home.\par
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender\par
# log4j.appender.A2=org.apache.log4j.RollingFileAppender\par
# log4j.appender.A2.File=d:/Integration/log/Test.log\par
log4j.appender.A2.File=/matsys01/t10001/DTI/Integration/logs/Integration.log\par
\par
# Truncate 'test' if it aleady exists.\par
log4j.appender.A2.Append=true\par
\par
# Appender A2 uses the PatternLayout.\par
log4j.appender.A2.layout=org.apache.log4j.PatternLayout\par
log4j.appender.A2.DatePattern='.'yyyy-MM-dd\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
drifter
Ranch Hand

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

log4j.logger.com.foo=WARN,A3
log4j.logger.com.bar=DEBUG,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)
log4j.additivity.com.foo=false
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: logs of different package to be written to different logs
 
Similar Threads
customize appenders within rootCategory
thread safe logging in a servlet
Logging
Log4j logs debug into info...
Frontman 2 FileNotFoundException ?