Changeset 25952

Show
Ignore:
Timestamp:
16.07.2012 21:42:00 (7 years ago)
Author:
ak19
Message:

Because gsdl3.home (web home) is no longer a property in global.properties, the server.log file was not being found and initialised on time. It is now explicitly being initialised in Server3.java, as was already happening for Server2.java as well.

Location:
main/trunk/greenstone3/src/java/org/greenstone/server
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java

    r25635 r25952  
    1818import java.util.StringTokenizer; 
    1919 
    20 import org.apache.log4j.*; 
     20import org.apache.log4j.PropertyConfigurator; 
    2121 
    2222import org.greenstone.util.PortFinder; 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server3.java

    r25951 r25952  
    22 
    33import java.io.File; 
     4import java.io.FileInputStream; 
     5import java.io.FileOutputStream; 
     6import java.util.Properties; 
    47 
    5 import org.greenstone.util.RunAnt; 
     8import org.apache.log4j.PropertyConfigurator; 
    69 
    710import org.greenstone.server.BaseServer; 
    811import org.greenstone.server.BaseProperty; 
    912import org.greenstone.util.GlobalProperties; 
     13import org.greenstone.util.RunAnt; 
    1014 
    1115public class Server3 extends BaseServer 
     
    4347    } 
    4448 
     49    public String fallbackGSDL3Home()  
     50    {  
     51        return gsdl_home + File.separator + "web"; //System.getenv("GSDL3SRCHOME") + File.separator + "web";  
     52    }  
     53 
    4554    public void reload() 
    4655    { 
    47         String fallback_gsdl3_home = System.getenv("GSDL3SRCHOME") + File.separator + "web"; 
    48         GlobalProperties.loadGlobalProperties(fallback_gsdl3_home); // properties file may have changed, so reload it 
     56        GlobalProperties.loadGlobalProperties(fallbackGSDL3Home()); // properties file may have changed, so reload it 
    4957    } 
    5058 
     
    6876        new Server3(gsdl3_src_home, lang); 
    6977    } 
     78 
     79    // Prepare the log4j.properties for GS3 
     80    protected void initLogger() { 
     81 
     82    String gsdl3_home = GlobalProperties.getGSDL3Home(); // may not be initialised at this stage     
     83    if(gsdl3_home == null) { // use gsdl_home/web 
     84        gsdl3_home = fallbackGSDL3Home(); 
     85    } 
     86    String propsFolder = gsdl3_home + File.separator + "WEB-INF" + File.separator + "classes" + File.separator; 
     87    File propsFile = new File(propsFolder+"log4j.properties"); 
     88 
     89    // create it from the template file GS3/resources/java/log4j.properties.in 
     90    if(!propsFile.exists()) { 
     91        try { 
     92        // need to set gsdl3.home property's value to be gsdl_home/web, 
     93        // so that the location  of the log files gets resolved correctly 
     94         
     95        // load the template log4j.properties.in file into logProps 
     96        FileInputStream infile = new FileInputStream(new File(gsdl_home+File.separator+"resources"+File.separator+"java"+File.separator+"log4j.properties.in")); 
     97        if(infile != null) { 
     98            Properties logProps = new Properties(); 
     99            logProps.load(infile); 
     100            infile.close(); 
     101 
     102            // set gsdl3.home to web home 
     103            logProps.setProperty("gsdl3.home", gsdl3_home); 
     104             
     105            // write the customised properties out to a custom log4j.properties file 
     106            FileOutputStream outfile = new FileOutputStream(propsFile); 
     107            if(outfile != null) { 
     108            logProps.store(outfile, "Customised log4j.properties file"); 
     109            outfile.close(); 
     110            } else { 
     111            System.err.println("Could not store properties file " + propsFile + " for Server3."); 
     112            } 
     113        } 
     114        } catch(Exception e) { 
     115        System.err.println("Exception occurred when custom-configuring the logger for Server3.\n" + e); 
     116        e.printStackTrace(); 
     117        } 
     118    } 
     119 
     120    // now configure the logger with the custom log4j.properties file 
     121    if(propsFile.exists()) { 
     122        PropertyConfigurator.configure(propsFile.getAbsolutePath()); 
     123    } else { 
     124        System.err.println("Could not create properties file " + propsFile + " for Server3."); 
     125    } 
     126    } 
    70127}