log pid and tid roughly same as logcat does

This commit is contained in:
Eric House 2020-04-17 18:07:50 -07:00
parent 6560394478
commit 0e5cc9f2b9
2 changed files with 10 additions and 5 deletions

View file

@ -1702,7 +1702,7 @@ public class GamesListDelegate extends ListDelegateBase
case R.id.games_menu_clearLogStorage: case R.id.games_menu_clearLogStorage:
makeConfirmThenBuilder( R.string.logstore_clear_confirm, makeConfirmThenBuilder( R.string.logstore_clear_confirm,
Action.CLEAR_LOG_DB ) Action.CLEAR_LOG_DB )
.setPosButton( R.string.button_delete ) .setPosButton( R.string.loc_item_clear )
.show(); .show();
break; break;
case R.id.games_menu_dumpLogStorage: case R.id.games_menu_dumpLogStorage:

View file

@ -26,6 +26,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment; import android.os.Environment;
import android.os.Process;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -242,11 +243,13 @@ public class Log {
void store( LOG_LEVEL level, String tag, String msg ) void store( LOG_LEVEL level, String tag, String msg )
{ {
long tid = Thread.currentThread().getId(); int tid = Process.myTid();
int pid = Process.myPid();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put( COL_ENTRY, msg ); values.put( COL_ENTRY, msg );
values.put( COL_THREAD, tid ); values.put( COL_THREAD, tid );
values.put( COL_PID, pid );
values.put( COL_TAG, tag ); values.put( COL_TAG, tag );
values.put( COL_LEVEL, level.ordinal() ); values.put( COL_LEVEL, level.ordinal() );
long res = getWritableDatabase().insert( LOGS_TABLE_NAME, null, values ); long res = getWritableDatabase().insert( LOGS_TABLE_NAME, null, values );
@ -262,7 +265,7 @@ public class Log {
OutputStream os = new FileOutputStream( db ); OutputStream os = new FileOutputStream( db );
OutputStreamWriter osw = new OutputStreamWriter(os); OutputStreamWriter osw = new OutputStreamWriter(os);
String[] columns = { COL_ENTRY, COL_TAG, COL_THREAD }; String[] columns = { COL_ENTRY, COL_TAG, COL_THREAD, COL_PID };
String selection = null; String selection = null;
String orderBy = COL_ROWID; String orderBy = COL_ROWID;
Cursor cursor = getReadableDatabase().query( LOGS_TABLE_NAME, columns, Cursor cursor = getReadableDatabase().query( LOGS_TABLE_NAME, columns,
@ -272,12 +275,14 @@ public class Log {
int indx0 = cursor.getColumnIndex( columns[0] ); int indx0 = cursor.getColumnIndex( columns[0] );
int indx1 = cursor.getColumnIndex( columns[1] ); int indx1 = cursor.getColumnIndex( columns[1] );
int indx2 = cursor.getColumnIndex( columns[2] ); int indx2 = cursor.getColumnIndex( columns[2] );
int indx3 = cursor.getColumnIndex( columns[3] );
while ( cursor.moveToNext() ) { while ( cursor.moveToNext() ) {
String data = cursor.getString(indx0); String data = cursor.getString(indx0);
String tag = cursor.getString(indx1); String tag = cursor.getString(indx1);
long tid = cursor.getLong(indx2); int tid = cursor.getInt(indx2);
int pid = cursor.getInt(indx3);
StringBuilder builder = new StringBuilder() StringBuilder builder = new StringBuilder()
.append(tid).append(":") .append(String.format("% 5d % 5d", pid, tid)).append(":")
.append(tag).append(":") .append(tag).append(":")
.append(data).append("\n") .append(data).append("\n")
; ;