package com.eactive.eai.common.property;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import com.eactive.eai.common.util.LogKeys;
import com.eactive.eai.common.util.Logger;

public class FileLoggerPropertyChangeListener implements PropertyChangeListener {

	private static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);

	@Override
	public void propertyChange(PropertyChangeEvent evt) {

		PropManager prptManager = PropManager.getInstance();
		PropGroupVO propGroupVO = (PropGroupVO)evt.getSource();
		String loggerNames = prptManager.getProperty(LogKeys.LOGGER_INFO, LogKeys.INITIAL_LOGGER_LIST);
		
		if ( loggerNames != null && 
				loggerNames.contains( propGroupVO.getName() ) ) {
			
			if ( logger.isDebugEnabled() ) {
				logger.debug("FileLoggerPropertyChangeListener propertyChange() " + propGroupVO.getName() );			
			}
			Logger.setLoggerLevel(propGroupVO.getName());
		}
	}

	@Override
    public boolean equals(Object obj) {
        return obj instanceof FileLoggerPropertyChangeListener;
    }
	
}
