For an android app I'm saving logs on the device itself so that when there are issues we can find out what they are. This device runs in a no internet environment so it's not an option to write the logs remotely.
The below code first clears the buffer, then continuously writes whatever is logged to 'logFile'.
try {
Process process = Runtime.getRuntime().exec("logcat -c"); // -c clear buffer.
process = Runtime.getRuntime().exec("logcat -f " + logFile + " -r 5120 -n 30"); // -r amount of bits to write, -n amount of logs to rotate
} catch ( IOException e ) {
e.printStackTrace();
}
This code works fine, except after some time, hours or days it randomly stops saving the log.
What might cause this and how can I fix this?
The problem was the app used a browser which did javascript requests. Occassionally these requests failed, but they were never cleaned up because no response came. This specific app is on 24/7 meaning it doesn't get to clear these requests in the normal way. Because this browser is using it's own sandbox no errors are thrown when this happens but at some point the memory fills up causing it to have no memory left to continue logging. Hence the problem of no memory is not logged. The fix in this case was to clear and restart the in-app browser every 6 hours, which fixed the problem.
This only happened on a specific Siemens tablet with a specific Android build.