FileDocCategorySizeDatePackage
LoggerChannelImpl.javaAPI DocAzureus 3.0.3.47913Sat Nov 18 15:27:02 GMT 2006org.gudy.azureus2.pluginsimpl.local.logging

LoggerChannelImpl

public class LoggerChannelImpl extends Object implements LoggerChannel
author
parg

Fields Summary
private static final LogIDs
LOGID
private org.gudy.azureus2.plugins.logging.Logger
logger
private String
name
private boolean
timestamp
private boolean
no_output
private List
listeners
private org.gudy.azureus2.core3.util.AEDiagnosticsLogger
diagnostic_logger
Constructors Summary
protected LoggerChannelImpl(org.gudy.azureus2.plugins.logging.Logger _logger, String _name, boolean _timestamp, boolean _no_output)

	
	
	
				
				
				
				 
	
		logger		= _logger;
		name		= _name;
		timestamp	= _timestamp;
		no_output	= _no_output;
	
Methods Summary
private intLogTypePluginToCore(int pluginLogType)

    switch (pluginLogType) {
      case LT_INFORMATION:
        return LogEvent.LT_INFORMATION;
      case LT_WARNING:
        return LogEvent.LT_WARNING;
      case LT_ERROR:
        return LogEvent.LT_ERROR;
    }
    return LogEvent.LT_INFORMATION;
  
public voidaddListener(LoggerChannelListener l)

		listeners.add( l );
	
protected java.lang.StringaddTimeStamp(java.lang.String data)

		if ( timestamp  ){
			
			return( getTimeStamp() + data );
			
		}else{
			
			return( data );
		}
	
private static java.lang.Stringformat(int n)

		if (n < 10){
	   	
			return( "0" + n );
	   }
		
	   return( String.valueOf(n));
	
public org.gudy.azureus2.plugins.logging.LoggergetLogger()

		return( logger );
	
public java.lang.StringgetName()

		return( name );
	
protected java.lang.StringgetTimeStamp()

		Calendar now = GregorianCalendar.getInstance();
    
		String timeStamp =
			"[" + now.get(Calendar.HOUR_OF_DAY)+ ":" + format(now.get(Calendar.MINUTE)) + ":" + format(now.get(Calendar.SECOND)) + "] ";        

		return( timeStamp );
	
public booleanisEnabled()

		return org.gudy.azureus2.core3.logging.Logger.isEnabled();
	
public voidlog(java.lang.String data)

		log( LT_INFORMATION, data );
	
public voidlog(java.lang.Object[] relatedTo, int log_type, java.lang.String data)

		
		notifyListeners(log_type, addTimeStamp(data));
		
		if (isEnabled() && !no_output) {
			data = "[" + name + "] " + data;
			org.gudy.azureus2.core3.logging.Logger.log(new LogEvent(relatedTo, LOGID,
					LogTypePluginToCore(log_type), data));
		}
	
public voidlog(java.lang.Object relatedTo, int log_type, java.lang.String data)

		log(new Object[] { relatedTo }, log_type, data);
	
public voidlog(java.lang.Throwable error)

    log("", error);
  
public voidlog(java.lang.String str, java.lang.Throwable error)

		notifyListeners(str.equals("") ? "" : addTimeStamp(str), error);

		if (!no_output) {
			LogEvent event = new LogEvent(LOGID, "[" + name + "] " + str, error);
			org.gudy.azureus2.core3.logging.Logger.log(event);
		}
	
public voidlog(java.lang.Object[] relatedTo, java.lang.String str, java.lang.Throwable error)

		notifyListeners(str.equals("") ? "" : addTimeStamp(str), error);

		if (isEnabled() && !no_output) {
			str = "[" + name + "] " + str;
			
			org.gudy.azureus2.core3.logging.Logger.log(new LogEvent(relatedTo, LOGID,
					str, error));
		}
	
public voidlog(java.lang.Object relatedTo, java.lang.String str, java.lang.Throwable error)

		log(new Object[] { relatedTo }, str, error);
	
public voidlog(java.lang.Object[] relatedTo, java.lang.String data)

		log(relatedTo, LT_INFORMATION, data);
	
public voidlog(java.lang.Object relatedTo, java.lang.String data)

		log(relatedTo, LT_INFORMATION, data);
	
public voidlog(int log_type, java.lang.String data)

		notifyListeners(log_type, addTimeStamp(data));

		if (isEnabled() && !no_output) {
			data = "[" + name + "] " + data;

			org.gudy.azureus2.core3.logging.Logger.log(new LogEvent(LOGID,
					LogTypePluginToCore(log_type), data));
		}
	
protected voidlogAlert(int alert_type, java.lang.String message, boolean repeatable)

		// output as log message to any listeners
		for (int i = 0; i < listeners.size(); i++) {
			try {
				((LoggerChannelListener) listeners.get(i)).messageLogged(alert_type,
						addTimeStamp(message));
			} catch (Throwable e) {
				Debug.printStackTrace(e);
			}
		}

		if (!no_output) {
			int at;

			switch (alert_type) {
				case LoggerChannel.LT_INFORMATION: {
					at = LogAlert.AT_INFORMATION;
					break;
				}
				case LoggerChannel.LT_WARNING: {
					at = LogAlert.AT_WARNING;
					break;
				}
				default: {
					at = LogAlert.AT_ERROR;
					break;
				}
			}

			org.gudy.azureus2.core3.logging.Logger.log(new LogAlert(repeatable, at,
					message));
		}
	
public voidlogAlert(int alert_type, java.lang.String message)

		logAlert( alert_type, message, false );
	
public voidlogAlert(java.lang.String message, java.lang.Throwable e)

		for (int i=0;i<listeners.size();i++){
			
			try{
				((LoggerChannelListener)listeners.get(i)).messageLogged( addTimeStamp( message ), e );
	
			}catch( Throwable f ){
				
				Debug.printStackTrace( f );
			}
		}	

		if ( !no_output ){
			org.gudy.azureus2.core3.logging.Logger.log(new LogAlert(
					LogAlert.UNREPEATABLE, message, e));
		}
	
public voidlogAlertRepeatable(int alert_type, java.lang.String message)

		logAlert( alert_type, message, true );
	
public voidlogAlertRepeatable(java.lang.String message, java.lang.Throwable e)

		for (int i=0;i<listeners.size();i++){
			
			try{
				((LoggerChannelListener)listeners.get(i)).messageLogged( addTimeStamp( message ), e );
	
			}catch( Throwable f ){
				
				Debug.printStackTrace( f );
			}
		}	
		
		if ( !no_output ){
			org.gudy.azureus2.core3.logging.Logger.log(new LogAlert(
					LogAlert.REPEATABLE, message, e));
		}
	
private voidnotifyListeners(int log_type, java.lang.String data)

		for (int i = 0; i < listeners.size(); i++) {
			try {
				LoggerChannelListener l = (LoggerChannelListener) listeners.get(i);
				l.messageLogged(log_type, data);
			} catch (Throwable e) {
				Debug.printStackTrace(e);
			}
		}
	
private voidnotifyListeners(java.lang.String listenersText, java.lang.Throwable error)

		for (int i = 0; i < listeners.size(); i++) {
			try {
				LoggerChannelListener l = (LoggerChannelListener) listeners.get(i);
				l.messageLogged(listenersText, error);
			} catch (Throwable e) {
				Debug.printStackTrace(e);
			}
		}
	
public voidremoveListener(LoggerChannelListener l)

		listeners.remove(l);
	
public voidsetDiagnostic()

		if ( diagnostic_logger == null ){
			
			diagnostic_logger = AEDiagnostics.getLogger( FileUtil.convertOSSpecificChars( name ));
			
			addListener(
				new LoggerChannelListener()
				{
					public void
					messageLogged(
						int		type,
						String	content )
					{
						diagnostic_logger.log( content );
					}
					
					public void
					messageLogged(
						String		str,
						Throwable	error )
					{
						diagnostic_logger.log( str );
						diagnostic_logger.log( error );
					}
				});
		}