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

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

Description

log Error

Declaration

public static void logError(Object 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);
    }//from   www  .j av  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. logd(String msg)
  2. loge(String msg)
  3. logi(String msg)
  4. logw(String msg)
  5. log(String text)
  6. logError(String errorClass, String msg, Exception e)
  7. e(Class clazz, String message)
  8. write(String path, String log)
  9. LogE(String tag, String message)