From d16f364a9df0e2abe0d41889eb4b696bbeb3ca31 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 15 Sep 2005 09:08:21 +0000 Subject: [PATCH] Logger moved to prefs so that class not found error can be handled in main --- src/jalview/bin/Cache.java | 41 ++++++++++++++++++++++++++++++++++- src/jalview/bin/Jalview.java | 45 +++++++++++---------------------------- src/jalview/ws/Discoverer.java | 30 +++++++++++++------------- src/jalview/ws/JPredClient.java | 16 +++++++------- src/jalview/ws/MsaWSClient.java | 2 +- 5 files changed, 77 insertions(+), 57 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 480bf5d..0013c63 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -23,6 +23,10 @@ import java.io.*; import java.util.*; import java.net.*; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.apache.log4j.Level; +import org.apache.log4j.ConsoleAppender; /** @@ -30,7 +34,7 @@ import java.net.*; *

Current properties include: *
logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services) *
logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization) - *
logs.Jalview.Level - Jalview.log stringified level. + *
logs.Jalview.Level - Cache.log stringified level. *
DISCOVERY_START - Boolean - controls if discovery services are queried on startup *
DISCOVERY_URLS - comma separated list of Discovery Service endpoints. *
SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_Y=285,SCREEN_X=371,SHOW_FULLSCREEN @@ -43,6 +47,10 @@ import java.net.*; */ public class Cache { + /** + * Initialises the Apache Axis logger + */ + public static Logger log; /** Jalview Properties */ public static Properties applicationProperties = new Properties(); @@ -50,6 +58,37 @@ public class Cache /** Default file is ~/.jalview_properties */ static String propertiesFile; + public static void initLogger() + { + try + { + Logger laxis = Logger.getLogger("org.apache.axis"); + Logger lcastor = Logger.getLogger("org.exolab.castor"); + jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview"); + + laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level", + Level.INFO.toString()))); + lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level", + Level.INFO.toString()))); + jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault( + "logs.Jalview.level", + Level.INFO.toString()))); + + ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(), + "System.err"); + ap.setName("JalviewLogger"); + + laxis.addAppender(ap); + lcastor.addAppender(ap); + jalview.bin.Cache.log.addAppender(ap); + } + catch (Exception ex) + { + System.err.println("Problems initializing the log4j system\n"); + } + } + + /** Called when Jalview is started */ public static void loadProperties(String propsFile) { diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index e780f78..9a85471 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -37,28 +37,6 @@ import java.util.Vector; */ public class Jalview { - /** - * Initialises the Apache Axis logger - */ - public static Logger log; - private static void initLogger() - { - Logger laxis = Logger.getLogger("org.apache.axis"); - Logger lcastor = Logger.getLogger("org.exolab.castor"); - log = Logger.getLogger("jalview.bin.Jalview"); - - laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level", Level.INFO.toString()))); - lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level", Level.INFO.toString()))); - log.setLevel(Level.toLevel(Cache.getDefault("logs.Jalview.level", Level.INFO.toString()))); - - ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(), - "System.err"); - ap.setName("JalviewLogger"); - - laxis.addAppender(ap); - lcastor.addAppender(ap); - log.addAppender(ap); - } /** * main class for Jalview application @@ -110,17 +88,20 @@ public class Jalview headless = true; } - Cache.loadProperties(aparser.getValue("props")); - - try - { - initLogger(); - } - catch (Exception e) - { - System.err.println("Problems initializing the log4j system\n"); - } + try + { + Cache.initLogger(); + } + catch (java.lang.NoClassDefFoundError error) + { + error.printStackTrace(); + System.out.println( + "\nEssential logging libraries not found." + +"\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview"); + System.exit(0); + } + Cache.loadProperties(aparser.getValue("props")); Desktop desktop = null; if( !headless ) diff --git a/src/jalview/ws/Discoverer.java b/src/jalview/ws/Discoverer.java index a7f139f..b30a05f 100755 --- a/src/jalview/ws/Discoverer.java +++ b/src/jalview/ws/Discoverer.java @@ -93,7 +93,7 @@ public class Discoverer } catch (Exception ex) { - jalview.bin.Jalview.log.error( + jalview.bin.Cache.log.error( "Serious! Service location failed\nfor URL :" + WsURL + "\n", ex); @@ -127,20 +127,20 @@ public class Discoverer if (!urls.contains(u)) urls.add(u); else - jalview.bin.Jalview.log.info("Ignoring duplicate url in DISCOVERY_URLS list"); + jalview.bin.Cache.log.info("Ignoring duplicate url in DISCOVERY_URLS list"); } catch (Exception ex) { - jalview.bin.Jalview.log.warn( + jalview.bin.Cache.log.warn( "Problem whilst trying to make a URL from '" + ( (url != null) ? url : "")+"'"); - jalview.bin.Jalview.log.warn("This was probably due to a malformed comma separated list" + jalview.bin.Cache.log.warn("This was probably due to a malformed comma separated list" +" in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)"); - jalview.bin.Jalview.log.debug("Exception was ",ex); + jalview.bin.Cache.log.debug("Exception was ",ex); } } }catch(Exception ex) - {jalview.bin.Jalview.log.warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",ex);} + {jalview.bin.Cache.log.warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",ex);} if (urls.size()>0) return urls; return null; @@ -157,7 +157,7 @@ public class Discoverer } else { - jalview.bin.Jalview.log.debug("Setting default services"); + jalview.bin.Cache.log.debug("Setting default services"); services = new Hashtable(); // Muscle, Clustal and JPred. ServiceHandle[] defServices = { @@ -204,14 +204,14 @@ public class Discoverer ServiceHandles shs = null; try { - jalview.bin.Jalview.log.debug("Discovering services using " + location); + jalview.bin.Cache.log.debug("Discovering services using " + location); shs = locateWebService(location).getServices(); } catch (Exception e) { - jalview.bin.Jalview.log.debug("No Discovery service at " + + jalview.bin.Cache.log.debug("No Discovery service at " + location); - jalview.bin.Jalview.log.debug(e); + jalview.bin.Cache.log.debug(e); } if ( (shs != null) && shs.getServices().length > 0) @@ -237,7 +237,7 @@ public class Discoverer { if (!cat.contains(sh[i])) { - jalview.bin.Jalview.log.debug("A " + sh[i].getAbstractName() + + jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName() + " service called " + sh[i].getName() + " exists at " + sh[i].getEndpointURL() + "\n"); @@ -260,7 +260,7 @@ public class Discoverer disc_serv = new java.net.URL(sh[i].getEndpointURL()); if (!ServiceURLList.contains(disc_serv)) { - jalview.bin.Jalview.log.debug( + jalview.bin.Cache.log.debug( "Adding new discovery service at " + disc_serv); ServiceURLList.add(disc_serv); seenNewDiscovery = true; @@ -268,7 +268,7 @@ public class Discoverer } catch (Exception e) { - jalview.bin.Jalview.log.debug( + jalview.bin.Cache.log.debug( "Ignoring bad discovery service URL " + sh[i].getEndpointURL(), e); } @@ -287,7 +287,7 @@ public class Discoverer int s_url = 0; if (ServiceURLList==null) { - jalview.bin.Jalview.log.debug("No service endpoints to use for service discovery."); + jalview.bin.Cache.log.debug("No service endpoints to use for service discovery."); return; } while (s_url < ServiceURLList.size()) @@ -297,7 +297,7 @@ public class Discoverer buildServiceLists(sh, cat, sscat); } else { - jalview.bin.Jalview.log.warn( + jalview.bin.Cache.log.warn( "No services at " +((java.net.URL) ServiceURLList.get(s_url)) +" - check DISCOVERY_URLS property in .jalview_properties"); diff --git a/src/jalview/ws/JPredClient.java b/src/jalview/ws/JPredClient.java index 45d4bd1..9fe7e27 100755 --- a/src/jalview/ws/JPredClient.java +++ b/src/jalview/ws/JPredClient.java @@ -190,7 +190,7 @@ public class JPredClient "Timed out when communicating with server\nTry again later.\n")); } if (result.getState()==0) - jalview.bin.Jalview.log.debug("Finished "+jobId); + jalview.bin.Cache.log.debug("Finished "+jobId); if (result.isRunning()) { wsInfo.setStatus(WebserviceInfo.STATE_RUNNING); @@ -317,7 +317,7 @@ public class JPredClient "JPredWS Client: Failed to submit the prediction (Possibly a server error - see below)\n" + e.getMessage() + "\n"); - jalview.bin.Jalview.log.debug("Failed Submission",e); + jalview.bin.Cache.log.debug("Failed Submission",e); } } @@ -370,20 +370,20 @@ public class JPredClient try { - jalview.bin.Jalview.log.debug("Parsing output from JNet job."); + jalview.bin.Cache.log.debug("Parsing output from JNet job."); // JPredFile prediction = new JPredFile("C:/JalviewX/files/jpred.txt", "File"); jalview.io.JPredFile prediction = new jalview.io.JPredFile(result. getPredfile(), "Paste"); SequenceI[] preds = prediction.getSeqsAsArray(); - jalview.bin.Jalview.log.debug("Got prediction profile."); + jalview.bin.Cache.log.debug("Got prediction profile."); Alignment al; int FirstSeq; // the position of the query sequence in Alignment al boolean noMsa = true; // set if no MSA has been returned by JPred if ( (this.msa != null) && (result.getAligfile() != null)) { - jalview.bin.Jalview.log.debug("Getting associated alignment."); + jalview.bin.Cache.log.debug("Getting associated alignment."); // we ignore the returned alignment if we only predicted on a single sequence String format = jalview.io.IdentifyFile.Identify(result.getAligfile(), "Paste"); @@ -520,7 +520,7 @@ public class JPredClient */ wsInfo.setProgressText(OutputHeader); - jalview.bin.Jalview.log.debug("Finished parsing output."); + jalview.bin.Cache.log.debug("Finished parsing output."); AlignFrame af = new AlignFrame(al); Desktop.addInternalFrame(af, altitle, @@ -529,8 +529,8 @@ public class JPredClient } catch (Exception ex) { - jalview.bin.Jalview.log.warn("Exception whilst parsing JNet style secondary structure prediction."); - jalview.bin.Jalview.log.debug("Exception: ",ex); + jalview.bin.Cache.log.warn("Exception whilst parsing JNet style secondary structure prediction."); + jalview.bin.Cache.log.debug("Exception: ",ex); } } } diff --git a/src/jalview/ws/MsaWSClient.java b/src/jalview/ws/MsaWSClient.java index 214d120..253dfba 100755 --- a/src/jalview/ws/MsaWSClient.java +++ b/src/jalview/ws/MsaWSClient.java @@ -257,7 +257,7 @@ public class MsaWSClient throw (new Exception( "Timed out when communicating with server\nTry again later.\n")); } - jalview.bin.Jalview.log.debug("Result state " + result.getState() + + jalview.bin.Cache.log.debug("Result state " + result.getState() + "(ServerError=" + result.isServerError() + ")"); if (result.isRunning()) -- 1.7.10.2