You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2001/08/21 06:52:17 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/log Log.java LogHandler.java LogManager.java

costin      01/08/20 21:52:17

  Modified:    src/share/org/apache/tomcat/util/log Log.java
                        LogHandler.java LogManager.java
  Log:
  Few fixes here. The changes in startup showed few obscure bugs on log initialization.
  
  Note that LogManager is used as a guard on all sensitive accesses to Log. Now adding a
  channel will 'fix' all logs that were created earlier for the channel ( with default
  logger )
  
  This is important for loggers that are created before LogSetter module gets a chance
  to initialize the logging subsystem. In normal operation we don't do any logging before
  that anyway, but for debugging it's usefull ( and makes the package more usefull for
  use outside tomcat )
  
  Revision  Changes    Path
  1.6       +16 -4     jakarta-tomcat/src/share/org/apache/tomcat/util/log/Log.java
  
  Index: Log.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/log/Log.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Log.java	2001/03/02 04:11:42	1.5
  +++ Log.java	2001/08/21 04:52:17	1.6
  @@ -124,7 +124,7 @@
          sink/logger at runtime, and without requiring the log
          user to do any special action or be aware of the changes
       */
  -    private LogHandler proxy=new LogHandler(); // the default
  +    private LogHandler proxy; // the default
   
       // Used to get access to other logging channels.
       // Can be replaced with an application-specific impl.
  @@ -133,9 +133,10 @@
   
       // -------------------- Various constructors --------------------
   
  -    protected Log(String channel, String prefix, Object owner) {
  +    protected Log(String channel, String prefix, LogHandler proxy, Object owner) {
   	this.logname=channel;
   	this.prefix=prefix;
  +	this.proxy=proxy;
       }
   
       /**
  @@ -227,17 +228,28 @@
        *  have been created from the default LogManager, and 
        *  provide a special manager implemetation.
        */
  -    public static void setLogManager( LogManager lm ) {
  +    public static LogManager setLogManager( LogManager lm ) {
   	// can be changed only once - so that user
   	// code can't change the log manager in running servers
   	if( logManager.getClass() == LogManager.class ) {
  +	    LogManager oldLM=logManager;
   	    logManager=lm;
  +	    return oldLM;
   	}
  +	return null;
       }
   
  +    public String  getChannel( LogManager lm ) {
  +	if( lm != logManager ) return null;
  +	return logname;
  +    }
  +
       public void setProxy( LogManager lm, LogHandler l ) {
   	// only the manager can change the proxy
  -	if( lm!= logManager ) return;
  +	if( lm!= logManager ) {
  +	    System.out.println("Attempt to change proxy " + lm + " " + logManager);
  +	    return;
  +	}
   	proxy=l;
       }
   
  
  
  
  1.2       +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/util/log/LogHandler.java
  
  Index: LogHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/log/LogHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogHandler.java	2001/03/02 04:11:44	1.1
  +++ LogHandler.java	2001/08/21 04:52:17	1.2
  @@ -84,7 +84,7 @@
   public  class LogHandler {
   
       protected PrintWriter sink = defaultSink;
  -    protected int level = Log.WARNING;
  +    protected int level = Log.INFORMATION;
   
       
       /**
  
  
  
  1.2       +25 -13    jakarta-tomcat/src/share/org/apache/tomcat/util/log/LogManager.java
  
  Index: LogManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/log/LogManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogManager.java	2001/03/02 04:11:44	1.1
  +++ LogManager.java	2001/08/21 04:52:17	1.2
  @@ -72,11 +72,19 @@
    **/
   public class LogManager {
   
  -    static LogHandler defaultChannel=null;
  +    static LogHandler defaultChannel=new LogHandler();
       
       protected Hashtable loggers=new Hashtable();
       protected Hashtable channels=new Hashtable();
   
  +    public  Hashtable getLoggers() {
  +	return loggers;
  +    }
  +
  +    public Hashtable getChannels() {
  +	return channels;
  +    }
  +    
       public static void setDefault( LogHandler l ) {
   	if( defaultChannel==null)
   	    defaultChannel=l;
  @@ -86,32 +94,36 @@
   	if(name==null) name="";
   
   	channels.put( name, logH );
  +	Enumeration enum=loggers.keys();
  +	while( enum.hasMoreElements() ) {
  +	    String k=(String)enum.nextElement();
  +	    Log l=(Log)loggers.get( k );
  +	    if( name.equals( l.getChannel( this ) )) {
  +		l.setProxy( this, logH );
  +	    }
  +	}
       }
       
       /** Default method to create a log facade.
        */
       public Log getLog( String channel, String prefix,
  -			  Object owner ) {
  +		       Object owner ) {
   	if( prefix==null && owner!=null ) {
   	    String cname = owner.getClass().getName();
   	    prefix = cname.substring( cname.lastIndexOf(".") +1);
   	}
   
  +	LogHandler proxy=(LogHandler)channels.get(channel);
  +	if( proxy==null ) proxy=defaultChannel;
  +	
   	// user-level loggers
  -	Log log=new Log( channel, prefix, owner );
  +	Log log=new Log( channel, prefix, proxy, owner );
   	loggers.put( channel + ":" + prefix, log );
  -
  -	// channels 
  -	LogHandler proxy=(LogHandler)channels.get(channel);
  -	if( proxy!= null ) {
  -	    log.setProxy( this, proxy );
  -	} else {
  -	    if( defaultChannel!=null )
  -		log.setProxy( this, defaultChannel );
  -	}
  -
  +	if( dL > 0 )
  +	    System.out.println("getLog facade " + channel + ":" + prefix);
   	return log;
       }
   
  +    private static int dL=0;
   
   }