How to log different package level to specific log file?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ian_sawchuk
Posted On:   Friday, January 14, 2005 08:29 AM

Hey all, On some older Log4j prop file I wrote up some time ago, i had my code writing logs based on the package where the class was logging. In each class I implemented this: private static final Category LOG = Category.getInstance(MyClass.class.getName()); So all my dao classes in com.foo.db would log to my db.log file due to the package name. All my data populators in com.foo.dh would log to dh.log and so on. I had a prop file that looked like this: ## setup log4j.category.com.foo.db = stdout,DbLogger log4j.category.com.foo.dh = stdout,DhLogger ### set DbLogger logging configurations l   More>>

Hey all,



On some older Log4j prop file I wrote up some time ago, i had my code writing logs based on the package where the class was logging. In each class I implemented this:



private static final Category LOG = Category.getInstance(MyClass.class.getName());


So all my dao classes in com.foo.db would log to my db.log file due to the package name. All my data populators in com.foo.dh would log to dh.log and so on. I had a prop file that looked like this:



## setup

log4j.category.com.foo.db = stdout,DbLogger

log4j.category.com.foo.dh = stdout,DhLogger




### set DbLogger logging configurations

log4j.appender.DbLogger.MaxFileSize = 50000000

log4j.appender.DbLogger.MaxBackupIndex = 20

log4j.appender.DbLogger= org.apache.log4j.ConsoleAppender

log4j.appender.DbLogger.layout = org.apache.log4j.PatternLayout

log4j.appender.DbLogger.layout.ConversionPattern =%d{dd-MMM-yyyy HH:mm:ss} %-7p %c{3} [%t] (%M) - %m%n

log4j.appender.DbLogger.File = c:logsdb.log

log4j.appender.DbLogger= org.apache.log4j.RollingFileAppender



...etc...



But I have now swapped my stuff around to use Logger properly and not the Category way. But in doing so, I cannot get my properties file to work.



Can anyone help or point me to a link that implements this? I can see how to get it to log to multiple files, but not based on how I used to reference the classpath of the class.

Thanks!

   <<Less

Re: How to log different package level to specific log file?

Posted By:   neeraj_pandey  
Posted On:   Thursday, January 27, 2005 08:29 PM

I am bit confused, what do you mean by - you want to use logger properly not the category way ? Do you want to have a single file not or still multiple...

I am bit confused. Sorry for this.
About | Sitemap | Contact