Android Open Source - cpustats My Log






From Project

Back to project page cpustats.

License

The source code is released under:

Apache License

If you think the Android project cpustats listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jp.takke.cpustats;
// w w w  .ja v  a2s  .c o m
import android.util.Log;

public class MyLog {
    
    public static boolean debugMode = false;
    
    public static void v(String msg) {
        if (debugMode) {
            Log.v(C.LOG_NAME, msg);
        }
    }

    public static void v(String msg, Throwable th) {
        if (debugMode) {
            Log.v(C.LOG_NAME, msg, th);
        }
    }

    
    public static void d(String msg) {
        if (debugMode) {
            Log.d(C.LOG_NAME, msg);
        }

        MyLog.dumpToExternalLogFile(Log.DEBUG, msg);
    }
    
    /**
     * msg ???? {elapsed} ?????????????????????????
     * 
     * @param msg ?????
     * @param startTick ??????[ms]
     */
    public static void dWithElapsedTime(String msg, long startTick) {
        
        if (debugMode) {
            d(msg.replace("{elapsed}", (System.currentTimeMillis() - startTick) + ""));
        }
    }
    
    public static void d(String msg, Throwable th) {
        
        if (debugMode) {
            Log.d(C.LOG_NAME, msg, th);
        }
        
        MyLog.dumpToExternalLogFile(Log.DEBUG, msg);
        MyLog.dumpToExternalLogFile(Log.DEBUG, Log.getStackTraceString(th));
    }

    
    public static void i(String msg) {
        Log.i(C.LOG_NAME, msg);

        MyLog.dumpToExternalLogFile(Log.INFO, msg);
    }

    public static void iWithElapsedTime(String msg, long startTick) {
        
        i(msg.replace("{elapsed}", (System.currentTimeMillis() - startTick) + ""));
    }
    
    public static void i(String msg, Throwable th) {
        Log.i(C.LOG_NAME, msg, th);

        MyLog.dumpToExternalLogFile(Log.INFO, msg);
        MyLog.dumpToExternalLogFile(Log.INFO, Log.getStackTraceString(th));
    }

    
    public static void w(String msg) {
        Log.w(C.LOG_NAME, msg);
        
        MyLog.dumpToExternalLogFile(Log.WARN, msg);
    }

    public static void wWithElapsedTime(String msg, long startTick) {
        
        if (debugMode) {
            w(msg.replace("{elapsed}", (System.currentTimeMillis() - startTick) + ""));
        }
    }
    
    public static void w(String msg, Throwable th) {
        Log.w(C.LOG_NAME, msg, th);

        MyLog.dumpToExternalLogFile(Log.WARN, msg);
        MyLog.dumpToExternalLogFile(Log.WARN, Log.getStackTraceString(th));
    }

    public static void w(Throwable th) {
        Log.w(C.LOG_NAME, th.getMessage(), th);

        MyLog.dumpToExternalLogFile(Log.WARN, Log.getStackTraceString(th));
    }

    
    public static void e(String msg) {
        Log.e(C.LOG_NAME, msg);
        
        MyLog.dumpToExternalLogFile(Log.ERROR, msg);
    }

    public static void e(String msg, Throwable th) {
        Log.e(C.LOG_NAME, msg, th);
        
        MyLog.dumpToExternalLogFile(Log.ERROR, msg);
        MyLog.dumpToExternalLogFile(Log.ERROR, Log.getStackTraceString(th));
    }

    public static void e(Throwable th) {
        Log.e(C.LOG_NAME, th.getMessage(), th);
        
        MyLog.dumpToExternalLogFile(Log.ERROR, Log.getStackTraceString(th));
    }

    /**
     * ???????(?????SD???)????????????
     * 
     * @param error ??????
     * @param msg ?????
     */
    private static void dumpToExternalLogFile(int error, String msg) {
        if (!debugMode) {
            return;
        }
            
//      try {
//          // ?????????
//          final File fout = TkUtil.getExternalStorageFile(C.EXTERNAL_FILE_DIRNAME, null);
//          if (fout == null) {
//              // ?????????????????
//              return;
//          }
//          final String path = fout.getAbsolutePath() + "/" + C.EXTERNAL_LOG_FILENAME;
//          
//          // ?????????????
//          final FileOutputStream out = new FileOutputStream(path, true);  // append
//
//          // ????
//          final SimpleDateFormat sdf = new SimpleDateFormat("[yyyy/MM/dd HH:mm:ss.SSS]");
//          out.write(sdf.format(new Date()).getBytes());
//          
//          // ??????
//          switch (error) {
//          case Log.INFO:  out.write("[INFO] ".getBytes());    break;
//          case Log.WARN:  out.write("[WARN] ".getBytes());    break;
//          case Log.ERROR: out.write("[ERROR] ".getBytes());   break;
//          case Log.DEBUG: out.write("[DEBUG] ".getBytes());   break;
//          default:
//              break;
//          }
//
//          // ????
//          out.write(msg.getBytes("UTF-8"));
//          out.write("\n".getBytes());
//          
//          out.flush();
//          out.close();
//          
//      } catch (Exception e) {
////            Log.e(C.LOG_NAME, e.getMessage(), e);
//      }
    }

    /**
     * ??????????????????????????????????????????????
     * 
     * ???????????????????????
     */
    public static void deleteBigExternalLogFile() {
        if (!debugMode) {
            return;
        }
        
//      try {
//          // ?????????
//          final File fout = TkUtil.getExternalStorageFile(C.EXTERNAL_FILE_DIRNAME, null);
//          if (fout == null) {
//              // ?????????????????
//              return;
//          }
//          final String path = fout.getAbsolutePath() + "/" + C.EXTERNAL_LOG_FILENAME;
//          
//          // ????????
//          final File file = new File(path);
//          final int MAXFILESIZE = 2 * 1024 * 1024;    // [MB]
//          
//          Log.i(C.LOG_NAME, "external log size check, size[" + file.length() + "], limit[" + MAXFILESIZE + "]");
//          
//          if (file.length() > MAXFILESIZE) {
//              file.delete();
//          }
//          
//      } catch (Exception e) {
//          Log.e(C.LOG_NAME, e.getMessage(), e);
//      }
    }

}




Java Source Code List

jp.takke.cpustats.BootReceiver.java
jp.takke.cpustats.C.java
jp.takke.cpustats.ConfigActivity.java
jp.takke.cpustats.MyAsyncTask.java
jp.takke.cpustats.MyLog.java
jp.takke.cpustats.MyUtil.java
jp.takke.cpustats.PreviewActivity.java
jp.takke.cpustats.QuadResourceUtil.java
jp.takke.cpustats.QuadResourceUtil.java
jp.takke.cpustats.ResourceUtil.java
jp.takke.cpustats.UsageUpdateService.java