Hi, Can any body help me,
We are creating log file using log4j Category class for this purpose I have created one class file for that and it's working properly .Problem is this I would like to log only messages that will loged by using my class file but few other classes which instantiates the Category file also writes messages into my log file . How can I keep my log file separate from other log file. pls find the code of class file created by me and property file. errorLog.properties log4j.rootCategory=DEBUG, dest1,R log4j.appender.dest1=org.apache.log4j.ConsoleAppender log4j.appender.dest1.layout=org.apache.log4j.PatternLayout #### Second appender writes to a file log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=c:\\weblogic\\khare.log # Control the maximum log file size log4j.appender.R.MaxFileSize=100KB # Archive log files (one backup file here) log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern= %d{dd MMM yyyy HH:mm:ss} - %m%n Class file import org.apache.log4j.Category; import org.apache.log4j.PropertyConfigurator; /** * To log Error messages into Log file. * */ public class ErrorUtil { static Category cat=Category.getInstance(ErrorUtil.class.toString()); private ErrorUtil() { } public static void logError(Hashtable errorMessages) { PropertyConfigurator.configure("c:\\weblogic\\errorLog.PROPERTIES"); System.out.println("logError called errorMessages= "+errorMessages); String logMessageString=null; int numberOfObject=0; try{ if(errorMessages.containsKey("client_ip")) logMessageString=(String)errorMessages.get("client_ip"); if(errorMessages.containsKey("user_agent")) logMessageString=logMessageString+","+ (String)errorMessages.get("user_agent"); if(errorMessages.containsKey("session_id")) logMessageString= logMessageString +"," + (String)errorMessages.get("session_id"); if(errorMessages.containsKey("weblogic_server_id")) logMessageString= logMessageString +","+ (String)errorMessages.get("weblogic_server_id"); if(errorMessages.containsKey("session_creation_time")) logMessageString= logMessageString +"," + (String)errorMessages.get("session_creation_time"); if(errorMessages.containsKey("error_message")) logMessageString= logMessageString +"," + (String)errorMessages.get("error_message"); if(errorMessages.containsKey("error_code")) logMessageString= logMessageString +"," + (String)errorMessages.get("error_code"); if(errorMessages.containsKey("customer_id")) logMessageString= logMessageString +"," + (String)errorMessages.get("customer_id"); if(errorMessages.containsKey("NumberOfObject")) numberOfObject= Integer.parseInt((String)errorMessages.get("NumberOfObject")); for(int count=1;count<=numberOfObject;count++) { if(errorMessages.containsKey("objectName"+count)) { logMessageString= logMessageString + "," +errorMessages.get("objectName"+count); } if(errorMessages.containsKey("objectValue"+count)) { logMessageString= logMessageString + "," + errorMessages.get("objectValue"+count); } } // Any objects attached to the session System.out.println("final Error message is "+logMessageString); cat.error(logMessageString); } catch(Exception e) { System.out.println("Exception occured "+e); } }//end of method logError(). public static String getErrorMessage(String exception) throws NullPointerException { exception= exception.substring(exception.lastIndexOf(".")+1,exception.length()); exception=exception.trim(); if(exception.indexOf(" ")!= -1) { exception= exception.substring(0,exception.indexOf(" ")-1); }//end of if. if(exception.indexOf(":")!= -1) { exception= exception.substring(0,exception.indexOf(":")); }//end of if. return exception; }//end of method getErrorMessage(). }//End of class. Regards, Shailesh khare HCL Tech,Noida. Tel:4516321 ext: 1095. ____________________________________________________________________________ _ DISCLAIMER: This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed. This communication represents the originator's personal views and opinions, which do not necessarily reflect those of HCL Technologies. If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify [EMAIL PROTECTED] -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>