Hello everyone, I am using commons logging for my application that uses log4j as such.
I want to have seperate log files for different application usage.For Example, all SQL logs should be logged into a file called SQL_LOG.txt and similar is the case with all logs for exceptions should be logged into seperate file.
This requirement needs 5 seperate log files to be created.So can you suggest me what changes need to be done as far as configuration in LOG4J is concerned.
A sample log4j.properties file would be appreciated where anyone can highlight the change to be done.
Thanks in advance, Saurabh
Success is not doing extraordinary things but doing ordinary things extraordinarily well.
There's no problem in declaring multiple loggers in one file. You can start out by duplicating your single logger 5 times, giving them different names and pointing them at different files.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Oct 07, 2003
Originally posted by Ulf Dittmer: There's no problem in declaring multiple loggers in one file. You can start out by duplicating your single logger 5 times, giving them different names and pointing them at different files.
I agree we can duplicate the logger multiple times and specify different file names but the question is in my JAVA code when i declare a logger like: private static final Logger logger = Logger.getLogger(Test.class);
So if i use the instance of the logger to log , then it would dump to which log file, how would it know which log file to dump.
So i am still there itself.Please think it from development perspective in JAVA.
Using logger.debug("::: Test Debug :::"); would dump into which log file as i have define 5 loggers in my log4j.xml file
Thanks Mahesh, but you dint get me .. i said i want to log to differnt files .. and i have hell lot of classes in my code, so i cant explicitly point to any class as same loging strategy would be used in multiple classes.
So in that case , how can i log to multiple files based on my exceptions.
For eg, SQL exceptions in sql.log, database exceptions in Db.log
Can you help me witha sample snippet specifying different file names
Joined: Dec 14, 2004
There are 2 ways u can do it.
I have successfully implemented the first method. The second one Iam unsure about, since it did not work for me.