Changeset 13123


Ignore:
Timestamp:
2006-10-17T15:44:38+13:00 (18 years ago)
Author:
shaoqun
Message:

added the code to use log4j and replace system.out or system.err to logger.info or logger.error respectively. The log file is in web/logs/greenstone.log

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r9874 r13123  
    3333import java.util.HashMap;
    3434
     35import org.apache.log4j.*;
     36
    3537/**
    3638 * Represents a collection in Greenstone. A collection is an extension of
     
    4345public class Collection
    4446    extends ServiceCluster {
     47
     48    static Category logger = Category.getInstance(org.greenstone.gsdl3.collection.Collection.class.getName());
    4549
    4650    protected XMLTransformer transformer = null;
     
    6973   
    7074    if (this.site_home == null || this.cluster_name== null) {
    71         System.err.println("Collection: site_home and collection_name must be set before configure called!");
     75        logger.error("Collection: site_home and collection_name must be set before configure called!");
    7276        return false;
    7377    }
     
    97101   
    98102    if (!coll_config_file.exists()) {
    99         System.err.println("Collection: couldn't configure collection: "+this.cluster_name+", "+coll_config_file+" does not exist");
     103        logger.error("Collection: couldn't configure collection: "+this.cluster_name+", "+coll_config_file+" does not exist");
    100104        return null;
    101105    }
     
    117121    File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
    118122    if (!build_config_file.exists()) {
    119         System.err.println("Collection: couldn't configure collection: "+this.cluster_name+", "+build_config_file+" does not exist");
     123        logger.error("Collection: couldn't configure collection: "+this.cluster_name+", "+build_config_file+" does not exist");
    120124        return null;
    121125    }
     
    176180    }
    177181   
    178     System.err.println("Collection: cant process system request, configure "+subset);
     182    logger.error("Collection: cant process system request, configure "+subset);
    179183    return false;
    180184    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r9874 r13123  
    3636import java.util.Iterator;
    3737
     38import org.apache.log4j.*;
     39
    3840/* ServiceCluster - a groups of services that are related in some way
    3941 * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself.
     
    4547public class ServiceCluster 
    4648    implements ModuleInterface {
     49
     50    static Category logger = Category.getInstance(org.greenstone.gsdl3.collection.ServiceCluster.class.getName());
    4751
    4852    protected static final String CONFIG_ENCODING = "utf-8";
     
    134138
    135139    if (this.site_home == null || this.cluster_name== null) {
    136         System.err.println("ServiceCluster: site_home and cluster_name must be set before configure called!");
    137         return false;
    138     }
    139     System.out.println("configuring service cluster");
     140        logger.error("site_home and cluster_name must be set before configure called!");
     141        return false;
     142    }
     143    logger.info("configuring service cluster");
    140144    // read the site configuration file
    141145    File config_file = new File(GSFile.siteConfigFile(this.site_home));
    142146
    143147    if (!config_file.exists()) {
    144         System.err.println("ServiceCluster: couldn't configure cluster: "+this.cluster_name +", "+config_file+" does not exist");
     148        logger.error("couldn't configure cluster: "+this.cluster_name +", "+config_file+" does not exist");
    145149        return false;
    146150    }
     
    148152    Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING);
    149153    if (doc == null) {
    150         System.err.println("ServiceCluster: couldn't parse config file "+config_file.getPath());
     154        logger.error("couldn't parse config file "+config_file.getPath());
    151155        return false;
    152156    }
     
    168172        if (!addMetadata(meta_list)) {
    169173       
    170         System.err.println("ServiceCluster: couldn't configure the metadata");
     174        logger.error(" couldn't configure the metadata");
    171175        }
    172176    }
     
    177181        if (!addDisplayItems(display_list)) {
    178182       
    179         System.err.println("ServiceCluster: couldn't configure the display items");
     183        logger.error("couldn't configure the display items");
    180184        }
    181185    }
     
    187191        // is this an error? could you ever have a service cluster
    188192        // without service racks???
    189         System.err.println("ServiceCluster: cluster has no service racks!!");
     193        logger.error("cluster has no service racks!!");
    190194    } else {
    191195       
    192196        if (!configureServiceRack(service_rack_list, null)) {
    193         System.err.println("ServiceCluster: couldn't configure the  service racks!!");
     197        logger.error("couldn't configure the  service racks!!");
    194198        return false;
    195199        }
     
    255259    NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
    256260    if (nodes.getLength()==0) {
    257         System.err.println("ServiceCluster configuration error: cluster "+this.cluster_name+" has no service modules!");
     261        logger.error("ServiceCluster configuration error: cluster "+this.cluster_name+" has no service modules!");
    258262        return false;
    259263    }
     
    304308        }
    305309        } catch (Exception e) {
    306         System.err.println("ServiceCluster Error:  configure exception: couldn't create service module:org.greenstone.gsdl3.service."+servicetype+"\n"+e.getMessage() + e.getClass() );
     310        logger.error("configure exception: couldn't create service module:org.greenstone.gsdl3.service."+servicetype+"\n"+e.getMessage() + e.getClass() );
    307311        e.printStackTrace();
    308312        //return false;
     
    343347    Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
    344348    if (requests.getLength()==0) {
    345         System.err.println("ServiceCluster.process: no requests for cluster:"+this.cluster_name);
     349        logger.error("no requests for cluster:"+this.cluster_name);
    346350        // no requests
    347351        return mainResult; // for now
     
    354358        String clustername = GSPath.getFirstLink(to);
    355359        if (!clustername.equals(this.cluster_name)){
    356         System.err.println("ServiceCluster Error: cluster name wrong! was "+clustername+" should have been "+this.cluster_name);
     360        logger.error("cluster name wrong! was "+clustername+" should have been "+this.cluster_name);
    357361        continue; // ignore this request
    358362        }
     
    368372       
    369373        if (!this.service_map.containsKey(service)) {
    370             System.err.println("ServiceCluster Error: non-existant service, "+service+", specified!");
     374            logger.error("non-existant service, "+service+", specified!");
    371375            continue;
    372376        }
     
    459463        response = processSystemRequest(request);
    460464    } else { // unknown type
    461         System.err.println("ServiceCluster Error: cant handle request of type "+ type);
     465        logger.error("cant handle request of type "+ type);
    462466       
    463467    }
     
    520524        response.appendChild(s);
    521525        } else {
    522         System.err.println("ServiceCluster: cant process system request, action "+action);
     526        logger.error("cant process system request, action "+action);
    523527        continue;
    524528        }
     
    534538    File configFile = new File(GSFile.siteConfigFile(this.site_home));
    535539    if (!configFile.exists() ) {
    536         System.err.println("ServiceCluster: site config file: "+configFile.getPath()+" not found!");
     540        logger.error("site config file: "+configFile.getPath()+" not found!");
    537541        // wont be able to do any of the requests
    538542        return false;
     
    542546    Document site_config_doc  = this.converter.getDOM(configFile);
    543547    if (site_config_doc == null) {
    544         System.err.println("ServiceCluster: could not read in site config file: "+configFile.getPath());
     548        logger.error("could not read in site config file: "+configFile.getPath());
    545549        return false;
    546550    }
     
    549553    Element cluster_config_elem = GSXML.getNamedElement((Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
    550554    if (cluster_config_elem == null) {
    551         System.err.println("ServiceCluster: site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
     555        logger.error("site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
    552556        // wont be able to do any of teh requests
    553557        return false;
     
    563567        return addMetadata(metadata_list);
    564568    } else {
    565         System.err.println("ServiceCluster: cant process system request, configure "+subset);
     569        logger.error("cannot process system request, configure "+subset);
    566570        return false;
    567571    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/XMLCollection.java

    r5266 r13123  
    1515import java.util.HashMap;
    1616
     17import org.apache.log4j.*;
     18
    1719/* for a collection that hasn't been built with greenstone build stuff. expects a documentList in the collectionConfig file, and it stores this. this is where doc level metadata comes from */
    1820public class XMLCollection
    1921    extends Collection {
     22
     23     static Category logger = Category.getInstance(org.greenstone.gsdl3.collection.XMLCollection.class.getName());
    2024
    2125    protected Element document_list = null;
     
    106110        response = processSystemRequest(request);
    107111    } else { // unknown type
    108         System.err.println("ServiceCluster Error: cant handle request of type "+ type);
     112        logger.error("cant handle request of type "+ type);
    109113       
    110114    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java

    r11022 r13123  
    3636import org.w3c.dom.Element;
    3737
     38import org.apache.log4j.*;
     39
    3840/*
    3941 * The Client side of a SOAP Connection
     
    4547public class SOAPCommunicator
    4648    extends Communicator {
     49
     50      static Category logger = Category.getInstance(org.greenstone.gsdl3.comms.SOAPCommunicator.class.getName());
    4751
    4852    /** address of site to connect to */
     
    6165    String type = site_elem.getAttribute(GSXML.TYPE_ATT);
    6266    if (!type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) {
    63         System.err.println("SOAPCommunicator: wrong type of site");
     67        logger.error("wrong type of site");
    6468        return false;
    6569    }
    6670    remote_site_name_ = site_elem.getAttribute(GSXML.NAME_ATT);
    6771    if (remote_site_name_.equals("")) {
    68         System.err.println("SOAPCommunicator: must have name attribute in site element");
     72        logger.error("must have name attribute in site element");
    6973        return false;
    7074    }
     
    7276    String local_site_name = site_elem.getAttribute(GSXML.LOCAL_SITE_ATT);
    7377    if (remote_site_address_.equals("") && local_site_name.equals("")) {
    74         System.err.println("SOAPCommunicator: must have address or localSite attributes in site element");
     78        logger.error("must have address or localSite attributes in site element");
    7579        return false;
    7680    }
     
    8488        call_.setTargetEndpointAddress( new java.net.URL(remote_site_address_) );
    8589    } catch (Exception e) {
    86         System.err.println("SOAPCommunicator.configure() Error: Exception occurred "+e);
     90        logger.error("SOAPCommunicator.configure() Error: Exception occurred "+e);
    8791        return false;
    8892    }
     
    118122    if (message.getNamespaceURI() == null) {
    119123        message_to_send = GSXML.duplicateWithNewNameNS(message.getOwnerDocument(), message, "gs3:"+message.getTagName(), "urn:foo", true);
    120         //System.err.println("**"+new XMLConverter().getPrettyString(new_message));
    121124    }
    122125   
     
    158161    Element response = comm.process(request_elem);
    159162   
    160     System.err.println("response was "+converter.getPrettyString(response));
     163    logger.error("response was "+converter.getPrettyString(response));
    161164    }
    162165}
Note: See TracChangeset for help on using the changeset viewer.