|
@@ -1,15 +1,32 @@
|
|
|
package com.usai.util;
|
|
package com.usai.util;
|
|
|
|
|
|
|
|
|
|
+import java.io.BufferedWriter;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.FileFilter;
|
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
|
+import java.io.FileWriter;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
|
|
+import com.usai.redant.photo.RedAntApplication;
|
|
|
|
|
+import com.usai.redant.photo.R.string;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.Activity;
|
|
|
|
|
+import android.app.Application;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
import android.database.Cursor;
|
|
import android.database.Cursor;
|
|
|
|
|
+import android.os.Environment;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
public class dbgUtil
|
|
public class dbgUtil
|
|
|
{
|
|
{
|
|
|
-// static boolean ENABLE_DEBUG = true;
|
|
|
|
|
-// static boolean ENABLE_SQL_DEBUG = true;
|
|
|
|
|
-// final int DEBUG_LEVEL_NONE = 8;
|
|
|
|
|
-// static int DEBUG_LEVEL = Log.VERBOSE;
|
|
|
|
|
|
|
+ // static boolean ENABLE_DEBUG = true;
|
|
|
|
|
+ // static boolean ENABLE_SQL_DEBUG = true;
|
|
|
|
|
+ // final int DEBUG_LEVEL_NONE = 8;
|
|
|
|
|
+ // static int DEBUG_LEVEL = Log.VERBOSE;
|
|
|
|
|
|
|
|
// private static boolean m_dbgFlag = true;
|
|
// private static boolean m_dbgFlag = true;
|
|
|
/*
|
|
/*
|
|
@@ -23,53 +40,160 @@ public class dbgUtil
|
|
|
* Boolean.parseBoolean(context.getString(R.string.flag_debug)); return
|
|
* Boolean.parseBoolean(context.getString(R.string.flag_debug)); return
|
|
|
* this; }
|
|
* this; }
|
|
|
*/
|
|
*/
|
|
|
- public static void Logd(String tag,String msg)
|
|
|
|
|
|
|
+ public static void fileLog(String content)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ File dir = new File(Environment.getExternalStorageDirectory().getPath()
|
|
|
|
|
+ + "/redant/pop");
|
|
|
|
|
+ if (!dir.exists())
|
|
|
|
|
+ dir.mkdirs();
|
|
|
|
|
+
|
|
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
|
|
+ c.add(Calendar.MONDAY, -1);
|
|
|
|
|
+
|
|
|
|
|
+ String newtime = new SimpleDateFormat("yyyy-MM-dd").format(c
|
|
|
|
|
+ .getTimeInMillis());
|
|
|
|
|
+
|
|
|
|
|
+ File[] f = dir.listFiles();
|
|
|
|
|
+ for (int i = 0; i < f.length; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!f[i].isFile())
|
|
|
|
|
+ continue;
|
|
|
|
|
+ String n = f[i].getName();
|
|
|
|
|
+ if ((n != null) && (n.length() > 0))
|
|
|
|
|
+ {
|
|
|
|
|
+ int dot = n.lastIndexOf('.');
|
|
|
|
|
+ if ((dot > -1) && (dot < (n.length())))
|
|
|
|
|
+ {
|
|
|
|
|
+ n = n.substring(0, dot);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(newtime.compareTo(n)>0)
|
|
|
|
|
+ f[i].delete();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // dir.listfiles
|
|
|
|
|
+
|
|
|
|
|
+ String file = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
|
|
|
+ String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
|
|
|
|
+ .format(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ FileOutputStream outputStream = null;
|
|
|
|
|
+ // try
|
|
|
|
|
+ // {
|
|
|
|
|
+
|
|
|
|
|
+ // dir.createNewFile()
|
|
|
|
|
+ File logfile = new File(Environment.getExternalStorageDirectory()
|
|
|
|
|
+ .getPath() + "/redant/pop/" + file + ".log");
|
|
|
|
|
+
|
|
|
|
|
+ // int mode = Application.MODE_APPEND;
|
|
|
|
|
+ if (!logfile.exists())
|
|
|
|
|
+ {
|
|
|
|
|
+ // mode = Application.MODE_PRIVATE;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ logfile.createNewFile();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (IOException e)
|
|
|
|
|
+ {
|
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // outputStream
|
|
|
|
|
+ // =RedAntApplication.getInstance().openFileOutput("pop.log", mode);
|
|
|
|
|
+
|
|
|
|
|
+ String logtextString = timeStamp + " " + content;
|
|
|
|
|
+
|
|
|
|
|
+ FileWriter fw = null;
|
|
|
|
|
+ BufferedWriter bw = null;
|
|
|
|
|
+ String datetime = "";
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ RedAntApplication.loglock.writeLock().lock();
|
|
|
|
|
+
|
|
|
|
|
+ fw = new FileWriter(Environment.getExternalStorageDirectory()
|
|
|
|
|
+ .getPath() + "/redant/pop/" + file + ".log", true);//
|
|
|
|
|
+ // 创建FileWriter对象,用来写入字符流
|
|
|
|
|
+ bw = new BufferedWriter(fw); // 将缓冲对文件的输出
|
|
|
|
|
+ // String myreadline = datetime + "[]" + str;
|
|
|
|
|
+
|
|
|
|
|
+ bw.write(logtextString + "\n"); // 写入文件
|
|
|
|
|
+ bw.newLine();
|
|
|
|
|
+ bw.flush(); // 刷新该流的缓冲
|
|
|
|
|
+ bw.close();
|
|
|
|
|
+ fw.close();
|
|
|
|
|
+ RedAntApplication.loglock.writeLock().unlock();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (IOException e)
|
|
|
|
|
+ {
|
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ bw.close();
|
|
|
|
|
+ fw.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (IOException e1)
|
|
|
|
|
+ {
|
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static void Logd(String tag, String msg)
|
|
|
{
|
|
{
|
|
|
String pos = getTracePos();
|
|
String pos = getTracePos();
|
|
|
- Log.d(tag,msg+pos);
|
|
|
|
|
|
|
+ Log.d(tag, msg + pos);
|
|
|
}
|
|
}
|
|
|
-// public static void Log(int type, String tag, String msg)
|
|
|
|
|
-// {
|
|
|
|
|
-//// if (ENABLE_DEBUG == false)
|
|
|
|
|
-//// return;
|
|
|
|
|
-//// if (type < DEBUG_LEVEL)
|
|
|
|
|
-//// return;
|
|
|
|
|
-// String pos= getTracePos();
|
|
|
|
|
-// switch (type)
|
|
|
|
|
-// {
|
|
|
|
|
-// case Log.ASSERT:
|
|
|
|
|
-// Log.wtf(tag, msg+pos);
|
|
|
|
|
-// break;
|
|
|
|
|
-// case Log.DEBUG:
|
|
|
|
|
-// Log.d(tag, msg+pos);
|
|
|
|
|
-// break;
|
|
|
|
|
-// case Log.ERROR:
|
|
|
|
|
-// Log.e(tag, msg+pos);
|
|
|
|
|
-// break;
|
|
|
|
|
-// case Log.INFO:
|
|
|
|
|
-// Log.i(tag, msg+pos);
|
|
|
|
|
-// break;
|
|
|
|
|
-// case Log.VERBOSE:
|
|
|
|
|
-// Log.v(tag, msg+pos);
|
|
|
|
|
-// break;
|
|
|
|
|
-// case Log.WARN:
|
|
|
|
|
-// Log.w(tag, msg+pos);
|
|
|
|
|
-// break;
|
|
|
|
|
-// default:
|
|
|
|
|
-// Log.wtf("dbgUtil", "LOG TYPE ERROR!"+pos);
|
|
|
|
|
-// break;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // public static void Log(int type, String tag, String msg)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // // if (ENABLE_DEBUG == false)
|
|
|
|
|
+ // // return;
|
|
|
|
|
+ // // if (type < DEBUG_LEVEL)
|
|
|
|
|
+ // // return;
|
|
|
|
|
+ // String pos= getTracePos();
|
|
|
|
|
+ // switch (type)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // case Log.ASSERT:
|
|
|
|
|
+ // Log.wtf(tag, msg+pos);
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case Log.DEBUG:
|
|
|
|
|
+ // Log.d(tag, msg+pos);
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case Log.ERROR:
|
|
|
|
|
+ // Log.e(tag, msg+pos);
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case Log.INFO:
|
|
|
|
|
+ // Log.i(tag, msg+pos);
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case Log.VERBOSE:
|
|
|
|
|
+ // Log.v(tag, msg+pos);
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case Log.WARN:
|
|
|
|
|
+ // Log.w(tag, msg+pos);
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // default:
|
|
|
|
|
+ // Log.wtf("dbgUtil", "LOG TYPE ERROR!"+pos);
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
private static String getTracePos()
|
|
private static String getTracePos()
|
|
|
{
|
|
{
|
|
|
// StackTraceElement[] elements =
|
|
// StackTraceElement[] elements =
|
|
|
// Thread.currentThread().getStackTrace();
|
|
// Thread.currentThread().getStackTrace();
|
|
|
StackTraceElement element = Thread.currentThread().getStackTrace()[4];
|
|
StackTraceElement element = Thread.currentThread().getStackTrace()[4];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return " at " + element.getClassName() + "." + element.getMethodName()
|
|
return " at " + element.getClassName() + "." + element.getMethodName()
|
|
|
- + "("+element.getFileName()+":" + element.getLineNumber()+")" ;
|
|
|
|
|
|
|
+ + "(" + element.getFileName() + ":" + element.getLineNumber()
|
|
|
|
|
+ + ")";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void dbgCursorInfo(Cursor cursor, Context context/*
|
|
public static void dbgCursorInfo(Cursor cursor, Context context/*
|
|
@@ -77,21 +201,23 @@ public class dbgUtil
|
|
|
* TracePos
|
|
* TracePos
|
|
|
*/)
|
|
*/)
|
|
|
{
|
|
{
|
|
|
-// if (ENABLE_SQL_DEBUG == false)
|
|
|
|
|
-// return;
|
|
|
|
|
|
|
+ // if (ENABLE_SQL_DEBUG == false)
|
|
|
|
|
+ // return;
|
|
|
|
|
|
|
|
// ----------------------debug cursor-----------------------------------
|
|
// ----------------------debug cursor-----------------------------------
|
|
|
- Log.d("sql_dbg@dbgCursorInfo", getTracePos() + "Cursor size: " + cursor.getCount()
|
|
|
|
|
- + "; columns count: " + cursor.getColumnCount() + ";");
|
|
|
|
|
-// dbgUtil.Log(Log.DEBUG,"sql_dbg", getTracePos() + "Cursor size: " + cursor.getCount()
|
|
|
|
|
-// + "; columns count: " + cursor.getColumnCount() + ";");
|
|
|
|
|
|
|
+ Log.d("sql_dbg@dbgCursorInfo",
|
|
|
|
|
+ getTracePos() + "Cursor size: " + cursor.getCount()
|
|
|
|
|
+ + "; columns count: " + cursor.getColumnCount() + ";");
|
|
|
|
|
+ // dbgUtil.Log(Log.DEBUG,"sql_dbg", getTracePos() + "Cursor size: " +
|
|
|
|
|
+ // cursor.getCount()
|
|
|
|
|
+ // + "; columns count: " + cursor.getColumnCount() + ";");
|
|
|
for (int i = 0; i < cursor.getColumnCount(); i++)
|
|
for (int i = 0; i < cursor.getColumnCount(); i++)
|
|
|
{
|
|
{
|
|
|
- Log.d("sql_dbg@dbgCursorInfo","column idx: " + i + "; column name: "
|
|
|
|
|
- + cursor.getColumnName(i) + ";");
|
|
|
|
|
-// dbgUtil.Log(Log.DEBUG,"sql_dbg",
|
|
|
|
|
-// "column idx: " + i + "; column name: "
|
|
|
|
|
-// + cursor.getColumnName(i) + ";");
|
|
|
|
|
|
|
+ Log.d("sql_dbg@dbgCursorInfo", "column idx: " + i
|
|
|
|
|
+ + "; column name: " + cursor.getColumnName(i) + ";");
|
|
|
|
|
+ // dbgUtil.Log(Log.DEBUG,"sql_dbg",
|
|
|
|
|
+ // "column idx: " + i + "; column name: "
|
|
|
|
|
+ // + cursor.getColumnName(i) + ";");
|
|
|
}
|
|
}
|
|
|
// ----------------------debug cursor-----------------------------------
|
|
// ----------------------debug cursor-----------------------------------
|
|
|
|
|
|