/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
* Corporate:
* EADS Astrium SAS
* EADS CRC
* Individual:
* Claude Cazenave
*
* $Id: LogConfigurator.java,v 1.4 2008/09/29 16:26:25 altournoud Exp $
*
* Changes
* -------
* 6 sept. 06 : Initial public release (CC);
*
*/
package simtools.logging;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.ConsoleHandler;
public class LogConfigurator extends simtools.util.LogConfigurator {
public LogConfigurator(Properties p, String prefix) {
super(p, prefix);
}
protected void configure(){
boolean useBinary = getBoolean("loggings.binary",true);
if(!useBinary){
super.configure();
}
else{
String loggingOut = getString("loggings.out", getDefaultFileHandlerPattern());
if(outHandlerList != null){
outHandlerList.clear();
}else{
outHandlerList= new ArrayList();
}
try{
int portId=Integer.parseInt(loggingOut);
String loggingHost = getString("loggings.host","localhost");
try {
outHandlerList.add(new SocketBufferHandler(loggingHost,portId));
} catch (IOException e) {
System.err.println("Logging can not connect with "+loggingHost+":"+portId);
}
}
catch(NumberFormatException nfe){
// if its not a number
if(loggingOut.length()!=0){
try {
outHandlerList.add(new FileBufferHandler(loggingOut));
} catch (SecurityException e) {
System.err.println("Security prevents logging into files");
} catch (IOException e) {
System.err.println("Can not log in "+loggingOut);
} catch (IllegalArgumentException e){
System.err.println("Invalid paremeters to log in "+loggingOut);
}
}
}
if(outHandlerList.size() == 0){
outHandlerList.add(new ConsoleHandler());
}
configureLevels();
}
}
protected String getDefaultFileHandlerPattern(){
boolean useBinary = getBoolean("loggings.binary",true);
if(!useBinary){
return super.getDefaultFileHandlerPattern();
}
else{
return propertyPrefix+".logb";
}
}
}