RE: Re: Urgent Please--How to create different log files with different property files in same webapplication

2007-06-27 Thread sivamma

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: Re: Urgent Please--How to create different log files with different property files in same webapplication

2007-06-26 Thread Bender Heri
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 = 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

RE: Re: Urgent Please--How to create different log files with different property files in same webapplication

2007-06-26 Thread sivamma

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]