RE: Re: Urgent Please--How to create different log files with different property files in same webapplication
Hi, Thank You So much. I am not very clear about repositoryselectors.I tried to check some examples and tried to implement. Our application will be used by others as a library.We will provide jsps ,jar files and some property files including log4j property file. All our property files will be under WEB-INF of their(XYZ's) web application.And our(abc's) jar files will be under their WEB-INF/lib.JSPs under XYZ/abc/*.jsp's. We are creating logs under WEB-INF/logs/abc.log We dont have access to XYZ's log4j config file.So we cant include loggers.What ever the changes, has to be made from our(abc) side only.I have already sent our log4j config file.I am new to log4j also.Please let me know if something can be done in our log4j config file. Can you please explain me how can i handle repository selectors for this problem.I am not able to find good examples also. Thanks Regards, Sivamma. Bender Heri wrote: Your Implementation of repository selector is quite useless, because your distinction criteria relies on the current classloader. Log4j's default repository selector does this already for you. It is a singleton within the scope of one distinct classloader. If annother classloader comes onto stage there will be created a new repository selector automatically. So each classloader context has its own separate logger universe which can be configured independently (i.e. each different WEB-INF app in Tomcat has its own classloader). A custom RepositorySelector has it's benefits if you can extract at a given time in code execution a unique criteria . This might differ when the same code is executed again (i.e. might be the user id of the logged in user, or others). How to establish this criteria is very dependent on the architecture of your application and your goal of separating the log outputs. I reviewd your mail-thread and I must admit I don't quite understand the relationship of your two applications abc and xyz. Nor do I understand which log statements you wish to be written to the one log file and which one to the other. If the distinction only relies on the code spot where the log output is generated then the best approach would be to define separate Loggers for your own classes (like james already mentioned), name them by the fully qualified classname and set the additivity flag to false. Like that log outputs issued by the classes of xyz app never reach the appenders of the classes of abc app and vice versa. But be aware: You cannot configure the same LogManager twice and hope the second configuration adds to the first one. The second configuration action will purge the first one before configuring new. But you can create new Loggers and Appenders by code and add them to the first loaded configuration. To give more precise advices you must explain more about the architecture of your applications. Heri -Original Message- From: sivamma [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 26, 2007 12:12 PM To: log4j-user@logging.apache.org Subject: [SPAM (Keyword Checking)] - Re: Urgent Please--How to create different log files with different property files in same webapplication - Found word(s) list error in the Text body Hi I tried to implement the repository selectors.But still problems occurs. Please find my repository selector below. However i am not using Servlets to initialize the log4j. So Even to implement repository selector i am not using servlets. Our customers requested us to not use servlets.Since we made everything using Java and jsps. == package com.CK; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.log4j.Hierarchy; import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.spi.RepositorySelector; import org.apache.log4j.spi.RootCategory; import java.io.File; import org.apache.log4j.Logger; import org.apache.log4j.Level; import org.apache.log4j.PropertyConfigurator; /** * This RepositorySelector is for use with web applications. * It assumes that your log4j.xml file is in the WEB-INF directory. * @author Stan Silvert */ public class Log4jSetup implements RepositorySelector { private static boolean initialized = false; // This object is used for the guard because it doesn't get // recycled when the application is redeployed. private static Object guard = LogManager.getRootLogger(); private static Map repositories = new HashMap(); private static LoggerRepository defaultRepository; /** * Register your web-app with this repository selector. */ public static String rPath = null; public Log4jSetup(String realPath) { rPath
Re: Urgent Please--How to create different log files with different property files in same webapplication
Hi I tried to implement the repository selectors.But still problems occurs. Please find my repository selector below. However i am not using Servlets to initialize the log4j. So Even to implement repository selector i am not using servlets. Our customers requested us to not use servlets.Since we made everything using Java and jsps. == package com.CK; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.log4j.Hierarchy; import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.spi.RepositorySelector; import org.apache.log4j.spi.RootCategory; import java.io.File; import org.apache.log4j.Logger; import org.apache.log4j.Level; import org.apache.log4j.PropertyConfigurator; /** * This RepositorySelector is for use with web applications. * It assumes that your log4j.xml file is in the WEB-INF directory. * @author Stan Silvert */ public class Log4jSetup implements RepositorySelector { private static boolean initialized = false; // This object is used for the guard because it doesn't get // recycled when the application is redeployed. private static Object guard = LogManager.getRootLogger(); private static Map repositories = new HashMap(); private static LoggerRepository defaultRepository; /** * Register your web-app with this repository selector. */ public static String rPath = null; public Log4jSetup(String realPath) { rPath = realPath; //ServletConfig config; init(); } public static synchronized void init() { //String realPath = getServletConfig().getServletContext().getRealPath(/); //rPath = realPath; if( !initialized ) // set the global RepositorySelector { defaultRepository = LogManager.getLoggerRepository(); RepositorySelector theSelector = new Log4jSetup(); LogManager.setRepositorySelector(theSelector, guard); initialized = true; } Hierarchy hierarchy = new Hierarchy(new RootCategory(Level.DEBUG)); loadLog4JConfig(hierarchy); ClassLoader loader = Thread.currentThread().getContextClassLoader(); repositories.put(loader, hierarchy); } // load config.properties from WEB-INF private static void loadLog4JConfig(Hierarchy hierarchy) { try { String filePath = rPath+File.separator+WEB-INF+File.separator+config.properties; String logfilePath = rPath+File.separator+WEB-INF+File.separator+logs+File.separator; if( !(new File(filePath)).isFile()) { System.err.println(ERROR:Log4jSetUp::Cannot read the Log4J configuration file. + Please check the path of the config init param in web.xml); } System.setProperty(ck.base,logfilePath); PropertyConfigurator.configure(filePath); } catch (Exception e) { System.err.println(Throws Exception::+e.getMessage()); } } private Log4jSetup() { } public LoggerRepository getLoggerRepository() { ClassLoader loader = Thread.currentThread().getContextClassLoader(); LoggerRepository repository = (LoggerRepository)repositories.get(loader); if (repository == null) { return defaultRepository; } else { return repository; } } } = Can you please tell me whats wrong with the code.Is there any other way to handle this?. Thanks Regards, Sivamma. Search the mailing list archives. I have never used them -- I am just somewhat familiar with what they do. -- View this message in context: http://www.nabble.com/Urgent-Please--How-to-create-different-log-files-with-different-property-files-in-same-webapplication-tf3974952.html#a11302960 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Re: Urgent Please--How to create different log files with different property files in same webapplication
Hi, Thank You So much. I am not very clear about repositoryselectors.I tried to check some examples and tried to implement. Our application will be used by others as a library.We will provide jsps ,jar files and some property files including log4j property file. All our property files will be under WEB-INF of their(XYZ's) web application.And our(abc's) jar files will be under their WEB-INF/lib.JSPs under XYZ/abc/*.jsp's. We are creating logs under WEB-INF/logs/abc.log We dont have access to XYZ's log4j config file.So we cant include loggers.What ever the changes, has to be made from our(abc) side only.I have already sent our log4j config file.I am new to log4j also.Please let me know if something can be done in our log4j config file. Can you please explain me how can i handle repository selectors for this problem.I am not able to find good examples also. Thanks Regards, Sivamma. -- View this message in context: http://www.nabble.com/Urgent-Please--How-to-create-different-log-files-with-different-property-files-in-same-webapplication-tf3974952.html#a11317767 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Urgent Please--How to create different log files with different property files in same webapplication
Hi, I have a requirement to create different log files in same application.Our application will be used in a different web application.Even the other application is using log4j.We have our own log4j configuration property(WEB-INF/config.properties) file and separate log file in a particular directory(WEB-INF/logs/xxx.log). At present the problem is we are getting logs from other application to our log file. Our application(Giving as jar files) is under other application. For example our application is abc and others is xyz. The directory structure is webapps/xyz/WEB-INF where it contains xyz's log4j property file as well abc's log4j property file.abc's logs are supposed to go webappas/xyz/WEB-INF/logs/abc.log and xyz's logs are supposed to go different file(Which we dont know , exactly where it goes). But at present xyz's logs are coming into abc's logs means , they are coming into webapps/xyz/WEB-INF/logs/abc.log Can you please tell me how can get logs only from my applicaiton(may not be from my application..only from my classes). Its little urgent. Thanks in advacne. Regards, Sivamma. -- View this message in context: http://www.nabble.com/Urgent-Please--How-to-create-different-log-files-with-different-property-files-in-same-webapplication-tf3974952.html#a11283346 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Urgent Please--How to create different log files with different property files in same webapplication
Hi, Thank you for immediate reply. The problem is little different here.XYZ and abc are in same application.XYZ is using abc's jar files and jsps. Our application(abc) have our own log4j configuration property file at WEB-INF folder of XYZ(WEB-INF is common for both of XYZ and abc). We are configuring log4j from java class file.We can not add/modify/delete XYZ's log4j configuration property file.At present we are getting even the XYZ's logs in our log files. Please find our log4j configuration(abc's) log4j.appender.mail.layout=org.apache.log4j.PatternLayout [EMAIL PROTECTED] log4j.appender.mail=org.apache.log4j.net.SMTPAppender log4j.appender.mail.SMTPPassword=xx log4j.appender.mail.BufferSize=512 log4j.appender.R.layout.ConversionPattern=%d{ MMM dd HH\:mm\:ss} -- %p -- %m%n log4j.appender.mail.evaluatorClass=com.CK.Evaluator log4j.appender.mail.SMTPUsername=siva log4j.appender.R.File=${ck.base}ck_logs.log log4j.rootCategory=debug, R,mail [EMAIL PROTECTED] log4j.appender.R.MaxBackupIndex=10 log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.mail.Threshold=WARN log4j.appender.mail.layout.ConversionPattern=%d{ MMM dd HH\:mm\:ss} -- %p -- %m%n log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.MaxFileSize=100KB log4j.appender.mail.Subject=\=[SMTPAppender] Application message log4j.appender.mail.SMTPHost=mail.abc.com It(abc) works fine as a single application in tomcat6. But when XYZ starts using abc the problem occurs(XYZ is using Weblogic Application server). Is there way to get separate the logs in a same application with different log4j configuration property files. Thanks Regards, Sivamma James Stauffer wrote: If xyz and abc are different web apps then moving log4j.jar and log4j.xml from common to WEB-INF/lib should keep the logs separate. If they are in the same web app then they probably have different logger name roots so you can configure each to use a different appender. (i.e com.abc uses one appender and com.xyz uses another appender). On 6/25/07, sivamma [EMAIL PROTECTED] wrote: Hi, I have a requirement to create different log files in same application.Our application will be used in a different web application.Even the other application is using log4j.We have our own log4j configuration property(WEB-INF/config.properties) file and separate log file in a particular directory(WEB-INF/logs/xxx.log). At present the problem is we are getting logs from other application to our log file. Our application(Giving as jar files) is under other application. For example our application is abc and others is xyz. The directory structure is webapps/xyz/WEB-INF where it contains xyz's log4j property file as well abc's log4j property file.abc's logs are supposed to go webappas/xyz/WEB-INF/logs/abc.log and xyz's logs are supposed to go different file(Which we dont know , exactly where it goes). But at present xyz's logs are coming into abc's logs means , they are coming into webapps/xyz/WEB-INF/logs/abc.log Can you please tell me how can get logs only from my applicaiton(may not be from my application..only from my classes). Its little urgent. Thanks in advacne. Regards, Sivamma. -- View this message in context: http://www.nabble.com/Urgent-Please--How-to-create-different-log-files-with-different-property-files-in-same-webapplication-tf3974952.html#a11283346 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- James Staufferhttp://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Urgent-Please--How-to-create-different-log-files-with-different-property-files-in-same-webapplication-tf3974952.html#a11286397 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Urgent Please--How to create different log files with different property files in same webapplication
We dont know exactly how log4j is handled at XYZ(They are our customers).But in abc , we are referring a config file through our code. Please find our java code. == package com.CK; import java.io.File; import org.apache.log4j.Logger; import org.apache.log4j.Level; import org.apache.log4j.PropertyConfigurator; public class Log4jSetup { public static String rPath = null; public Log4jSetup(String realPath) { rPath = realPath; } public Log4jSetup() { String filePath = rPath+File.separator+WEB-INF+File.separator+config.properties; String logfilePath = rPath+File.separator+WEB-INF+File.separator+logs+File.separator; if( !(new File(filePath)).isFile()) { System.err.println([CK]ERROR:Log4jSetUp::Cannot read the Log4J configuration file. ); } System.setProperty(ck.base,logfilePath); PropertyConfigurator.configure(filePath); Logger log = Logger.getLogger(Log4jSetup.class); } } = Thanks Regards, Sivamma. James Stauffer wrote: How exactly is log4j configured from abc and xyz? Directly through code? Code referencing a config file? log4j automatically finding a config file? On 6/25/07, sivamma [EMAIL PROTECTED] wrote: Hi, Thank you for immediate reply. The problem is little different here.XYZ and abc are in same application.XYZ is using abc's jar files and jsps. Our application(abc) have our own log4j configuration property file at WEB-INF folder of XYZ(WEB-INF is common for both of XYZ and abc). We are configuring log4j from java class file.We can not add/modify/delete XYZ's log4j configuration property file.At present we are getting even the XYZ's logs in our log files. Please find our log4j configuration(abc's) log4j.appender.mail.layout=org.apache.log4j.PatternLayout [EMAIL PROTECTED] log4j.appender.mail=org.apache.log4j.net.SMTPAppender log4j.appender.mail.SMTPPassword=xx log4j.appender.mail.BufferSize=512 log4j.appender.R.layout.ConversionPattern=%d{ MMM dd HH\:mm\:ss} -- %p -- %m%n log4j.appender.mail.evaluatorClass=com.CK.Evaluator log4j.appender.mail.SMTPUsername=siva log4j.appender.R.File=${ck.base}ck_logs.log log4j.rootCategory=debug, R,mail [EMAIL PROTECTED] log4j.appender.R.MaxBackupIndex=10 log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.mail.Threshold=WARN log4j.appender.mail.layout.ConversionPattern=%d{ MMM dd HH\:mm\:ss} -- %p -- %m%n log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.MaxFileSize=100KB log4j.appender.mail.Subject=\=[SMTPAppender] Application message log4j.appender.mail.SMTPHost=mail.abc.com It(abc) works fine as a single application in tomcat6. But when XYZ starts using abc the problem occurs(XYZ is using Weblogic Application server). Is there way to get separate the logs in a same application with different log4j configuration property files. Thanks Regards, Sivamma James Stauffer wrote: If xyz and abc are different web apps then moving log4j.jar and log4j.xml from common to WEB-INF/lib should keep the logs separate. If they are in the same web app then they probably have different logger name roots so you can configure each to use a different appender. (i.e com.abc uses one appender and com.xyz uses another appender). On 6/25/07, sivamma [EMAIL PROTECTED] wrote: Hi, I have a requirement to create different log files in same application.Our application will be used in a different web application.Even the other application is using log4j.We have our own log4j configuration property(WEB-INF/config.properties) file and separate log file in a particular directory(WEB-INF/logs/xxx.log). At present the problem is we are getting logs from other application to our log file. Our application(Giving as jar files) is under other application. For example our application is abc and others is xyz. The directory structure is webapps/xyz/WEB-INF where it contains xyz's log4j property file as well abc's log4j property file.abc's logs are supposed to go webappas/xyz/WEB-INF/logs/abc.log and xyz's logs are supposed to go different file(Which we dont know , exactly where it goes). But at present xyz's logs are coming into abc's logs means , they are coming into webapps/xyz/WEB-INF/logs/abc.log Can you please tell me how can get logs only from my applicaiton(may not be from my application..only from my classes). Its little urgent. Thanks in advacne. Regards, Sivamma. -- View this message in context: http://www.nabble.com/Urgent-Please--How-to-create-different-log-files-with-different-property-files-in-same-webapplication
Re: Urgent Please--How to create different log files with different property files in same webapplication
Can you please explain me more.How to implement repository selectors.Please send me some examples. I tried to find in FAQs and some docs.But its not clear to me. Thanks Regards, Sivamma. So does only your customer have the problem of mixed logs? It sounds like they just need to change their config if they don't want mixed logs. But knowing how customers can be repository selectors might keep the logs separate without the customer changing their config. -- View this message in context: http://www.nabble.com/Urgent-Please--How-to-create-different-log-files-with-different-property-files-in-same-webapplication-tf3974952.html#a11288789 Sent from the Log4j - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]