Changeset 8235


Ignore:
Timestamp:
2004-10-08T09:12:27+13:00 (20 years ago)
Author:
mdewsnip
Message:

Removed debug static variable. All debugging output should go to the new DebugStream class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r8233 r8235  
    110110    /** A static reference to ourselves. */
    111111    static public Gatherer self;
    112     /** The debug print stream. */
    113     static public PrintStream debug;
    114112    /** We are using the GLI for GS3 */
    115113    static public boolean GS3 = false;
     
    176174    }
    177175    // Create the debug stream only if required.
    178     if(debug_enabled) {
    179         try {
    180         Calendar now = Calendar.getInstance();
    181         StringBuffer name = new StringBuffer("debug");
    182         name.append(now.get(Calendar.DATE));
    183         name.append("-");
    184         name.append(now.get(Calendar.MONTH));
    185         name.append("-");
    186         name.append(now.get(Calendar.YEAR));
    187         name.append(".txt");
    188 
    189         // Debug file is created in the GLI directory, unless the GLI is running as an applet
    190         String debug_file_path = name.toString();
    191         if (isGsdlRemote) {
    192             debug_file_path = Utility.getGLIUserFolder().toString() + File.separator + debug_file_path;
    193         }
    194         Gatherer.println("Debug file path: " + debug_file_path);
    195         this.debug = new PrintStream(new FileOutputStream(debug_file_path));
    196 
    197         Properties props = System.getProperties();
    198         props.list(debug);
    199         }
    200         catch(Exception error) {
    201         ///ystem.err.println("Error in Gatherer.init(): " + error);
    202         error.printStackTrace();
    203         System.exit(1);
    204         }
     176    if (debug_enabled) {
     177        DebugStream.enableDebugging();
     178
     179        Calendar now = Calendar.getInstance();
     180        StringBuffer name = new StringBuffer("debug");
     181        name.append(now.get(Calendar.DATE));
     182        name.append("-");
     183        name.append(now.get(Calendar.MONTH));
     184        name.append("-");
     185        name.append(now.get(Calendar.YEAR));
     186        name.append(".txt");
     187
     188        // Debug file is created in the GLI directory, unless the GLI is running as an applet
     189        String debug_file_path = name.toString();
     190        if (isGsdlRemote) {
     191        debug_file_path = Utility.getGLIUserFolder().toString() + File.separator + debug_file_path;
     192        }
     193        DebugStream.println("Debug file path: " + debug_file_path);
     194        DebugStream.setDebugFile(debug_file_path);
     195        DebugStream.print(System.getProperties());
    205196    }
    206197    try {
     
    454445
    455446    // Flush debug
    456     if(debug != null) {
    457         try {
    458         debug.flush();
    459         debug.close();
    460         }
    461         catch (Exception error) {
    462         error.printStackTrace();
    463         }
    464     }
     447    DebugStream.closeDebugStream();
    465448
    466449    // If we started a server, we should try to stop it.
     
    632615    /** Print a message to the debug stream. */
    633616    static synchronized public void print(String message) {
    634     if(debug != null) {
    635         debug.print(message);
    636         System.err.print(message);
    637     }
     617    DebugStream.print(message);
    638618    }
    639619    /** Print a message to the debug stream. */
    640620    static synchronized public void println(String message) {
    641     if(debug != null) {
    642         debug.println(message);
    643         System.err.println(message);
    644     }
     621    DebugStream.println(message);
    645622    }
    646623
    647624    /** Print a stack trace to the debug stream. */
    648625    static synchronized public void printStackTrace(Exception exception) {
    649     if (debug != null) {
    650         exception.printStackTrace(debug);
    651     }
    652     exception.printStackTrace();
     626    DebugStream.printStackTrace(exception);
    653627    }
    654628
     
    985959            // mozilla and netscape, try using a remote command to get things in the same window
    986960            String [] new_commands = new String[] {prog_name, "-raise", "-remote", "openURL("+url+",new-tab)"};
    987             if(debug != null) {
    988             printArray(new_commands);
    989             }
     961            printArray(new_commands);
     962
    990963            Runtime rt = Runtime.getRuntime();
    991964            process = rt.exec(new_commands);
     
    993966            if (exitCode != 0) { // if Netscape or mozilla was not open
    994967            Gatherer.println("couldn't do remote, trying original command");
    995             if(debug != null) {
    996                 printArray(commands);
    997             }
     968            printArray(commands);
    998969            process = rt.exec(commands); // try the original command
    999970            }
     
    1026997    public void printArray(String [] array) {
    1027998        for(int i = 0; i < array.length; i++) {
    1028         debug.print(array[i]+" ");
     999        DebugStream.print(array[i]+" ");
    10291000        System.err.println(array[i]+" ");
    10301001        }
Note: See TracChangeset for help on using the changeset viewer.