Project

General

Profile

« Previous | Next » 

Revision 3269

Added by Jing Tao over 17 years ago

Add new method to write debug info to a given file.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatUtil.java
27 27
package edu.ucsb.nceas.metacat;
28 28

  
29 29
import java.io.File;
30
import java.io.FileOutputStream;
31
import java.io.FileWriter;
32
import java.io.PrintWriter;
33
import java.io.StringReader;
30 34
import java.net.MalformedURLException;
31 35
import java.net.URL;
36
import java.text.SimpleDateFormat;
32 37
import java.util.HashMap;
33 38
import java.util.Hashtable;
34 39
import java.util.Stack;
......
829 834
    	return (isAllowedSubmitter(username, groups) 
830 835
    			&& !isDeniedSubmitter(username, groups));
831 836
    }
837
    
838
    /**
839
     * Writes debug information into a file. In metacat.properties, if property writeDebugToFile is
840
     * set to true, the debug information will be written to debug file, which value is the property
841
     * debugOutputFile in metacat.properties.
842
     *
843
     */
844
    public static void writeDebugToFile(String debugInfo)
845
    {
846
    	String debug = MetaCatUtil.getOption("writeDebugToFile");
847
    	if (debug != null && debug.equalsIgnoreCase("true"))
848
    	{
849
    		 try
850
    		 {
851
    			 File outputFile = new File(MetaCatUtil.getOption("debugOutputFile"));   			 
852
    			 FileOutputStream fos = new FileOutputStream(outputFile, true);
853
                 PrintWriter pw = new PrintWriter(fos);
854
                 pw.println(debugInfo);
855
                 pw.flush();
856
                 pw.close();
857
    			 fos.close();
858
    			 
859
    		 }
860
    		 catch(Exception io)
861
    		 {
862
    			logMetacat.warn("Eorr in MetacatUtil.writeDebugToFile "+io.getMessage()) ;
863
    		 }
864
    	}
865
    	
866
    }
832 867
}

Also available in: Unified diff