Android Log logError(String errorClass, String msg, Exception e)

Here you can find the source of logError(String errorClass, String msg, Exception e)

Description

log Error

Declaration

public static void logError(String errorClass, String msg, Exception e) 

Method Source Code

//package com.java2s;

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileWriter;

import java.io.PrintWriter;
import java.io.StringWriter;

import android.util.Log;

public class Main {
    public static File logFile;
    public static boolean writeLogFile;

    public static void logError(Object errorClass, String msg, Exception e) {
        logError(errorClass.getClass().toString(), msg, e);
    }/* w ww  .  ja  v a 2s.  c  o m*/

    public static void logError(String errorClass, String msg, Exception e) {
        Log.e(errorClass, msg, e);

        if (writeLogFile && logFile != null) {
            String completeError = "\n" + "\n" + errorClass + " // " + msg
                    + " // " + e.getMessage() + "\n";
            StringWriter errors = new StringWriter();
            e.printStackTrace(new PrintWriter(errors));
            completeError += errors.toString() + "\n";

            writeLog(completeError);
        }
    }

    public static void writeLog(String msg) {
        try {
            // if file doesnt exists, then create it
            if (!logFile.exists()) {
                logFile.createNewFile();
            }

            FileWriter fw = new FileWriter(logFile.getAbsoluteFile(), true);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(msg);
            bw.close();
        } catch (Exception e) {
        }
    }
}

Related

  1. loge(String msg)
  2. logi(String msg)
  3. logw(String msg)
  4. log(String text)
  5. logError(Object errorClass, String msg, Exception e)
  6. e(Class clazz, String message)
  7. write(String path, String log)
  8. LogE(String tag, String message)
  9. debug(Object msg)