Here you can find the source of logException(String msg, Exception ex)
Parameter | Description |
---|---|
msg | the message to log |
ex | the exception to log |
public static void logException(String msg, Exception ex)
//package com.java2s; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.PrintWriter; public class Main { /**/*from w w w. j a v a 2s. c o m*/ * Logs the specified message and exception to * ./repast.log. * * @param msg the message to log * @param ex the exception to log */ public static void logException(String msg, Exception ex) { BufferedWriter out; PrintWriter pOut = null; try { out = new BufferedWriter(new FileWriter("./repast.log")); pOut = new PrintWriter(out); pOut.println(msg); ex.printStackTrace(pOut); pOut.flush(); pOut.close(); if (pOut.checkError()) { pOut.flush(); pOut.close(); System.err.println("Error while writing error log"); } } catch (Exception ex1) { try { if (pOut != null) { pOut.flush(); pOut.close(); } System.err.println("Error while writing error log"); ex1.printStackTrace(); } catch (Exception ex2) { } } } }