brouter/brouter-routing-app/src/main/java/btools/routingapp/AppLogger.java
Manuel Fuhr 54d5c5e943 Reformat files using Android Studio
android-studio/bin/format.sh -m '*.java' -r brouter-routing-app

To rebase active branches on top of the new master just rebase your
branch onto the commit prior to the reformatting and format every commit
of your branch using (<commit> should be replaced by this commit)

git rebase \
        --strategy-option=theirs \
        --onto <commit> \
        --exec 'format.sh -m "*.java" -r brouter-routing-app' \
        --exec 'git commit --all --no-edit --amend' \
        <commit>~

To ignore this mass edit during git blame see `.git-blame-ignore-revs`
2021-11-20 16:50:23 +01:00

70 lines
1.6 KiB
Java

package btools.routingapp;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import android.os.Environment;
/**
* static logger interface to be used in the android app
*/
public class AppLogger {
private static FileWriter debugLogWriter = null;
private static boolean initDone = false;
private static void init() {
try {
// open logfile if existing
File sd = Environment.getExternalStorageDirectory();
if (sd == null) return;
File debugLog = new File(sd, "Android/media/btools.routingapp/brouter/brouterapp.txt");
if (debugLog.exists()) {
debugLogWriter = new FileWriter(debugLog, true);
}
} catch (IOException ioe) {
}
}
/**
* log an info trace to the app log file, if any
*/
public static boolean isLogging() {
if (!initDone) {
initDone = true;
init();
log("logging started at " + new Date());
}
return debugLogWriter != null;
}
/**
* log an info trace to the app log file, if any
*/
public static void log(String msg) {
if (isLogging()) {
try {
debugLogWriter.write(msg);
debugLogWriter.write('\n');
debugLogWriter.flush();
} catch (IOException e) {
throw new RuntimeException("cannot write brouterapp.txt: " + e);
}
}
}
/**
* Format an exception using
*/
public static String formatThrowable(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
return sw.toString();
}
}