Return-Path: Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: (qmail 93025 invoked from network); 11 Apr 2007 00:09:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Apr 2007 00:09:13 -0000 Received: (qmail 82691 invoked by uid 500); 11 Apr 2007 00:09:16 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 82669 invoked by uid 500); 11 Apr 2007 00:09:16 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 82658 invoked by uid 99); 11 Apr 2007 00:09:16 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2007 17:09:16 -0700 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=INFO_TLD,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lists@nabble.com designates 72.21.53.35 as permitted sender) Received: from [72.21.53.35] (HELO talk.nabble.com) (72.21.53.35) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2007 17:09:09 -0700 Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1HbQOG-0005Uw-Ph for log4j-user@logging.apache.org; Tue, 10 Apr 2007 17:08:48 -0700 Message-ID: <9931051.post@talk.nabble.com> Date: Tue, 10 Apr 2007 17:08:48 -0700 (PDT) From: sohan To: log4j-user@logging.apache.org Subject: Re: separate log files for application's on weblogic with log4j using RepositorySelector In-Reply-To: <1176245821.461c163d237b1@my.visi.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: sohan.kasula@mms.gov References: <9908677.post@talk.nabble.com> <20070410044314.0942210FB007@herse.apache.org> <9926589.post@talk.nabble.com> <1176245821.461c163d237b1@my.visi.com> X-Virus-Checked: Checked by ClamAV on apache.org "What do you mean "'pcs' is the log file name"? That would be the logger name, not the file name." My mistake, I meant to say that it is both the logger name as well as I named the log file name same too after the application name. I tried with both LogFactory of commons-logging as well as direct use of Log4j. Behavior is the same I did notice one thing, Log information is being written normally from java classes that extend HttpServlet. Logging from other java class files is not working as intended. My application uses struts 1.2.9 too. thanks, Sohan Jacob Kjome wrote: > > Quoting sohan : > >> >> I changed to use Log4j.xml from Log4j.properties and also changed to >> non-static loggers and with in the static methods followed the link >> examples. Now the logging is taking place only for the loggers mentioned >> in >> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the log >> file >> name. >> > > What do you mean "'pcs' is the log file name"? That would be the logger > name, > not the file name. > > Also, I didn't mean to direct you to use commons-logging. If you were > using > log4j directly, please keep using it. In fact, log wrappers like SLF4J > and > commons-logging have issues when it comes to repository selectors. Search > the > SLF4J user list for details on this. There's also a bug in the SLF4J > database > about this. I believe the same applies to commons-logging. Log4j cannot > guarantee proper logging separation when you use a wrapper. > >> Any idea as to why the non static logger is not working! >> > > I would guess it's because you are using commons-logging. Use Log4j > directly, > just as you were previously. I only sent you the commons-logging link > because > they had a good synopsis of the static logger issue, not to convince you > to > move to commons-logging. > > > Jake > >> thanks, >> Sohan >> >> >> Jacob Kjome wrote: >> > >> > >> > 1. Use non-static loggers (for Serializable classes, you'll need to >> > mark these as transient) >> > 2. Avoid Classloader-based repository selectors. Use JNDI-base >> > selectors. There's already one written for Log4j-1.3alpha. Even if >> > you don't care to use 1.3, you can use it to get an idea of how to >> > write one for 1.2. >> > >> > >> > See: >> > http://www.qos.ch/logging/sc.jsp >> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog >> > >> > >> > Jake >> > >> > At 03:09 PM 4/9/2007, you wrote: >> > > >> > >I followed some examples on the web to use RepositorySelector to >> > implement >> > >separate logging for 2 applications deployed on the same instance of >> > >weblogic server. I have the Lgo4j.properties file under Web-Inf/ >> folder, >> > >This is loaded through web.xml file through a startup servlet. >> Problem >> > is >> > >logging is taking place either in Log4j.log file or other >> applications >> > log >> > >file. In each java class file, I use.. >> > > private static Logger log = >> Logger.getLogger(LoginFilter.class); >> > >and call the log .info ..accordingly. In log4j properties file, only >> > >difference is file name for 2 applications. >> > > >> > >I am using weblogic 8.1.6 and Log4j 1.2.8 versions >> > > >> > >thanks for the help >> > >Sohan >> > > >> > >web.xml entry... >> > > >> > > >> > > log4j-init >> > > >> pcs.common.util.Log4jInit >> > > >> > > Log4JProperties >> > > >> > /WEB-INF/log4j-dev.properties >> > > >> > > >> > > LogToFileOnly >> > > false >> > > >> > > 1 >> > > >> > > >> > >public class Log4jInit extends HttpServlet { >> > > static Logger log = Logger.getLogger(Log4jInit.class); >> > > public void init() throws ServletException { >> > > >> > System.out.println("\n\n---------------Log4jInit---------------\n\n"); >> > >> > > MyRepositorySelector.init(this.getServletConfig()); >> > > Logger log = Logger.getLogger(this.getClass()); >> > > log.info("Log message from Log4jInit servlet"); >> > > System.out.println("\n\n---------------Log4jInit: >> > >Complete---------------\n\n"); >> > > >> > > } >> > > >> > >} >> > > >> > >public class MyRepositorySelector implements RepositorySelector >> > >{ >> > > private static boolean initialized = false; >> > > private static Object guard = LogManager.getRootLogger(); >> > > >> > > private static Map repositories = new HashMap(); >> > > private static LoggerRepository defaultRepository; >> > > >> > > public static synchronized void init(ServletConfig config) >> > > throws ServletException { >> > > if( !initialized ) // set the global RepositorySelector >> > > { >> > > defaultRepository = LogManager.getLoggerRepository(); >> > > RepositorySelector theSelector = new MyRepositorySelector(); >> > > LogManager.setRepositorySelector(theSelector, guard); >> > > initialized = true; >> > > } >> > > >> > > Hierarchy hierarchy = new Hierarchy(new >> > RootCategory(Level.DEBUG)); >> > > loadLog4JConfig(config, hierarchy); >> > > ClassLoader loader = >> > Thread.currentThread().getContextClassLoader(); >> > > repositories.put(loader, hierarchy); >> > > } >> > > >> > > public static synchronized void removeFromRepository() { >> > > >> > repositories.remove(Thread.currentThread().getContextClassLoader()); >> > > } >> > > >> > > >> > > private static void loadLog4JConfig(ServletConfig config, >> > > Hierarchy hierarchy) >> > > throws ServletException { >> > > try { >> > > >> > > String strLogProperties = >> > > >> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES); >> > > System.out.println("strLogProperties: " + >> > strLogProperties); >> > > Properties logProperties = new Properties(); >> > > try { >> > > >> > >> >logProperties.load(config.getServletContext().getResourceAsStream(strL >> > >ogProperties)); >> > > } catch (Exception e) { >> > > System.out.println("ERROR: Loading log4j >> > properties: " + >> > >e.getMessage()); >> > > //e.printStackTrace(); >> > > } >> > > PropertyConfigurator propConf = new >> > PropertyConfigurator(); >> > > propConf.doConfigure(logProperties, hierarchy); >> > > } catch (Exception e) { >> > > throw new ServletException(e); >> > > } >> > > } >> > > >> > > private MyRepositorySelector() { >> > > } >> > > >> > > public LoggerRepository getLoggerRepository() { >> > > ClassLoader loader = >> > Thread.currentThread().getContextClassLoader(); >> > > LoggerRepository repository = >> > >(LoggerRepository)repositories.get(loader); >> > > >> > > if (repository == null) { >> > > return defaultRepository; >> > > } else { >> > > return repository; >> > > } >> > > } >> > >} >> > >-- >> > >View this message in context: >> > >> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog >> > >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677 >> > >Sent from the Log4j - Users mailing list archive at Nabble.com. >> > > >> > > >> > >--------------------------------------------------------------------- >> > >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> > >For additional commands, e-mail: log4j-user-help@logging.apache.org >> > >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> > For additional commands, e-mail: log4j-user-help@logging.apache.org >> > >> > >> > >> >> -- >> View this message in context: >> > http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589 >> Sent from the Log4j - Users mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> For additional commands, e-mail: log4j-user-help@logging.apache.org >> >> > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org > For additional commands, e-mail: log4j-user-help@logging.apache.org > > > -- View this message in context: http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051 Sent from the Log4j - Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.apache.org