Java Log Exception logException(String msg, Exception ex)

Here you can find the source of logException(String msg, Exception ex)

Description

Logs the specified message and exception to ./repast.log.

License

Open Source License

Parameter

Parameter Description
msg the message to log
ex the exception to log

Declaration

public static void logException(String msg, Exception ex) 

Method Source Code


//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) {
            }
        }
    }
}

Related

  1. logException(int type, String RID, String subRID, String propIndication, String error)
  2. logException(Logger logger, Level logLevel, Exception e)
  3. logException(Logger logger, String message, Throwable t)
  4. logException(Logger logger, Throwable t)
  5. LogException(String description, Throwable e)
  6. logException(Throwable t, Logger log, Level level)
  7. logStackTrace(Logger log, Throwable e)
  8. logStackTrace(Throwable e, Logger logger)