mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-21 01:57:08 -04:00
Logcat logging
This commit is contained in:
@@ -99,7 +99,7 @@ public class InstallModActivity extends AppCompatActivity
|
||||
|
||||
JREUtils.setJavaEnvironment(this);
|
||||
|
||||
JREUtils.redirectStdio(false);
|
||||
//JREUtils.redirectStdio(false);
|
||||
JREUtils.setJavaEnvironment(this);
|
||||
JREUtils.initJavaRuntime();
|
||||
JREUtils.chdir(Tools.MAIN_PATH);
|
||||
|
||||
@@ -24,17 +24,7 @@ public class JREUtils
|
||||
dlopen("libgl04es.so");
|
||||
}
|
||||
}
|
||||
|
||||
public static File redirectStdio(boolean current) throws ErrnoException {
|
||||
File logFile = new File(current ? Tools.datapath : Tools.MAIN_PATH, (current ? "current" : "latest") + "log.txt");
|
||||
|
||||
FileDescriptor fd = Os.open(logFile.getAbsolutePath(), OsConstants.O_WRONLY | OsConstants.O_CREAT | OsConstants.O_TRUNC, 0666);
|
||||
Os.dup2(fd, OsConstants.STDERR_FILENO);
|
||||
Os.dup2(fd, OsConstants.STDOUT_FILENO);
|
||||
|
||||
return logFile;
|
||||
}
|
||||
|
||||
public static native void redirectLogcat();
|
||||
public static void setJavaEnvironment(Context ctx) throws IOException, ErrnoException {
|
||||
String libName = System.getProperty("os.arch").contains("64") ? "lib64" : "lib";
|
||||
String ldLibraryPath = (
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.kdt.glsupport.*;
|
||||
import com.kdt.pointer.*;
|
||||
import dalvik.system.*;
|
||||
import java.io.*;
|
||||
import java.lang.Process;
|
||||
import java.lang.reflect.*;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
@@ -840,6 +841,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
|
||||
private FileObserver mLogObserver;
|
||||
private void runCraft() throws Throwable {
|
||||
/* Old logger
|
||||
if (Tools.LAUNCH_TYPE != Tools.LTYPE_PROCESS) {
|
||||
currLogFile = JREUtils.redirectStdio(true);
|
||||
// DEPRECATED constructor (String) api 29
|
||||
@@ -848,7 +850,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
public void onEvent(int event, String file) {
|
||||
try {
|
||||
if (event == FileObserver.MODIFY && currLogFile.length() > 0l) {
|
||||
appendToLog(Tools.read(currLogFile.getAbsolutePath()));
|
||||
System.out.println(Tools.read(currLogFile.getAbsolutePath()));
|
||||
Tools.write(currLogFile.getAbsolutePath(), "");
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
@@ -859,7 +861,26 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
};
|
||||
mLogObserver.startWatching();
|
||||
}
|
||||
|
||||
*/
|
||||
JREUtils.redirectLogcat();
|
||||
Log.v("jrelog","Log starts here");
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
Log.i("jrelog-logcat","Clearing logcat");
|
||||
new ProcessBuilder().command("logcat","-c").redirectErrorStream(true).start();
|
||||
Log.i("jrelog-logcat","Starting logcat");
|
||||
Process p = new ProcessBuilder().command("logcat","-v","brief","*:S").redirectErrorStream(true).start();
|
||||
byte[] buf = new byte[512];
|
||||
int len;
|
||||
while ((len = p.getInputStream().read(buf)) != -1) {
|
||||
appendToLog(new String(buf, 0, len));
|
||||
}
|
||||
}catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
Log.i("jrelog-logcat","Logcat thread started");
|
||||
Tools.launchMinecraft(this, mProfile, mVersionInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -642,16 +642,13 @@ public final class Tools
|
||||
|
||||
public static String convertStream(InputStream inputStream, Charset charset) throws IOException {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String line = null;
|
||||
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, charset))) {
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
stringBuilder.append(line);
|
||||
}
|
||||
String out = "";
|
||||
int len;
|
||||
byte[] buf = new byte[512];
|
||||
while((len = inputStream.read(buf))!=-1) {
|
||||
out += new String(buf,0,len,charset);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
return out;
|
||||
}
|
||||
|
||||
// Current Useless below but keep it for future usage.
|
||||
@@ -687,19 +684,16 @@ public final class Tools
|
||||
|
||||
return choice;
|
||||
}
|
||||
|
||||
public static byte[] getByteArray(String filePath) throws Exception
|
||||
{
|
||||
return getByteArray(new FileInputStream(filePath));
|
||||
}
|
||||
|
||||
public static byte[] getByteArray(InputStream stream) throws IOException {
|
||||
return IOUtils.toByteArray(stream);
|
||||
}
|
||||
|
||||
|
||||
public static String read(InputStream is) throws Exception {
|
||||
byte[] byteArr = getByteArray(is);
|
||||
return new String(byteArr, 0, byteArr.length);
|
||||
String out = "";
|
||||
int len;
|
||||
byte[] buf = new byte[512];
|
||||
while((len = is.read(buf))!=-1) {
|
||||
out += new String(buf,0,len);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String read(String path) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user