Laurent Duperval wrote:

Hi,

Is there a flag I can set so that Struts tells me what it's doing? I'm having a problem with one of my actions: when I click on it, I get a blank page and I don't understand why. I'd like to be able to see what decisions Sruts is taking in order to load my pages, to determine where I made a mistake in my config.

Thanks,

L


You are better off setting up a logging facility as other suggest. However, if you just want a temporary solution prior to doing that, you can use something like the following class, which you ahve to configure to send a log to where you want it.

public class StdOut {
private static final String slash = File.separator;
private static final String environment = Classpath.CLASSES;
private static final String path = "com" + slash + "crackwillow" + slash + "log" + slash+ "store" + slash;
private static final String fileName = "log.crackwillow";
private static final String logPath = environment + path;


 public static void log(Object input) {
   try {
     SaveOutput.start(environment + path + fileName);
     System.out.println(input.toString());
     new Exception();
   } catch (Exception e) {
     log("log.error",e.getMessage());
   } finally {
     SaveOutput.stop();
   }
 }

 public static void log(String fileName,
                        Object input) {
   fileName = logPath + fileName;
   try {
     SaveOutput.start(fileName);
     System.out.println(input.toString());
     new Exception();
   } catch (Exception e) {
     log("log.error",e.getMessage());
   } finally {
     SaveOutput.stop();
   }
 }

 public static void log(String input) {
   try {
     SaveOutput.start(environment + path + fileName);
     System.out.println(input);
     new Exception();
   } catch (Exception e) {
     log("log.error",e.getMessage());
   } finally {
     SaveOutput.stop();
   }
 }

 public static void log(String fileName,
                             String input) {
   fileName = logPath + fileName;
   try {
     SaveOutput.start(fileName);
     System.out.println(input);
     new Exception();
   } catch (Exception e) {
     log("log.error",e.getMessage());
   } finally {
     SaveOutput.stop();
   }
 }

 public static void log(boolean input) {
   try {
     SaveOutput.start(environment + path + fileName);
     System.out.println("" + input);
     new Exception();
   } catch (Exception e) {
     log("log.error",e.getMessage());
   } finally {
     SaveOutput.stop();
   }
 }

 public static void log(String fileName,
                             boolean input) {
   fileName = logPath + fileName;
   try {
     SaveOutput.start(fileName);
     System.out.println("" + input);
     new Exception();
   } catch (Exception e) {
     log("log.error",e.getMessage());
   } finally {
     SaveOutput.stop();
   }
 }
}

class SaveOutput
   extends PrintStream {

 static OutputStream logFile;
 static PrintWriter printer;
 static PrintStream oldStdOut;
 static PrintStream oldStdErr;

 /****************************************************
  * The print streams are out and err objects of the *
  * System class.  Println here overrides these.     *
  ****************************************************/
 SaveOutput(PrintStream ps) {
   super(ps);
 }

// Starts copying stdout and
// stderr to file
public static void start(String file) {
// Save the old settings
oldStdOut = System.out;
oldStdErr = System.err;
// Create and open a log file
try {
logFile = new PrintStream(new BufferedOutputStream(new FileOutputStream(file, true)));
} catch (FileNotFoundException fnfe) {
}
// Start redirecting the output
System.setOut(new SaveOutput(System.out));
System.setErr(new SaveOutput(System.err));
}


 // Restores the original settings of
 // stdout and stderr
 public static void stop() {
   System.setOut(oldStdOut);
   System.setErr(oldStdErr);
   try {
     logFile.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }

 public void println(String input) {
   ((PrintStream)logFile).println(input);
 }

private class Classpath {
public static final String HERE = Classpath.class.getClassLoader().getResource("com" + File.separator + "crackwillow" + File.separator + "classpath" + File.separator + "Classpath.class").getFile();
public static final String CLASSES = HERE.substring(0, HERE.lastIndexOf("com"));
}


}


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to