packagetest;importjava.io.File;importjava.io.FileOutputStream;importjava.io.PrintStream;importjava.util.Date;importandroid.os.Environment;public class Log extendsLogger {private static final String APP_TAG = "renwuto";private static final String LOG_FILE_NAME = "renwuto.txt";private staticPrintStream logStream;private static final String LOG_ENTRY_FORMAT = "[%tF %tT]%s";publicLog(String name) {super(name);
}
@Overrideprotected voiddebug(String str) {
android.util.Log.d(APP_TAG, str);
write(str,null);
}
@Overrideprotected voiderror(String str) {
android.util.Log.e(APP_TAG, str);
write(str,null);
}
@Overrideprotected voidinfo(String str) {
android.util.Log.i(APP_TAG, str);
write(str,null);
}
@Overrideprotected voidwarn(String str) {
android.util.Log.w(APP_TAG, str);
write(str,null);
}
@Overrideprotected voiddebug(String str, Throwable tr) {
android.util.Log.d(APP_TAG, str);
write(str, tr);
}
@Overrideprotected voiderror(String str, Throwable tr) {
android.util.Log.e(APP_TAG, str);
write(str, tr);
}
@Overrideprotected voidinfo(String str, Throwable tr) {
android.util.Log.i(APP_TAG, str);
write(str, tr);
}
@Overrideprotected voidwarn(String str, Throwable tr) {
android.util.Log.w(APP_TAG, str);
write(str, tr);
}private voidwrite(String msg, Throwable tr) {if (!Log.DBG) {return;
}try{if (null ==logStream) {synchronized (Log.class) {if (null ==logStream) {
init();
}
}
}
Date now= newDate();if (null !=logStream) {
logStream.printf(LOG_ENTRY_FORMAT, now, now, msg);
logStream.print("\n");
}if (null !=tr) {
tr.printStackTrace(logStream);if (null !=logStream) {
logStream.print("\n");
}
}
}catch(Throwable t) {//Empty catch block
}
}public static voidinit() {if (!Log.DBG) {return;
}try{
File sdRoot= null;
String state=Environment.getExternalStorageState();if(Environment.MEDIA_MOUNTED.equals(state)) {
sdRoot=Environment.getExternalStorageDirectory();
}if (sdRoot != null) {
File logFile= newFile(sdRoot, LOG_FILE_NAME);
android.util.Log.d(APP_TAG,"Log to file : " +logFile);
logStream= new PrintStream(new FileOutputStream(logFile, true), true);
}
}catch(Throwable e) {//Empty catch block
}
}
@Overrideprotected void finalize() throwsThrowable {try{super.finalize();if (logStream != null) {
logStream.close();
}
}catch(Throwable t) {//Empty catch block
}
}
}