Reputation: 14638
I have been trying to investigate a common issue that is happening in my turn-based app in prod. From some reason, at some point, the turns are messed up I have not been able to figure out the reason for that. So I decided to create a log file and send this log file when this issue happen.
I don't want to use log cat as it requires permission. I need to use my own logging file so user is assured that its only my logging statement. What do you recommend I do? Just open a file and append to it my logging statements, or is there a library that I can use that would work with android for logging to a file? Thank you
Upvotes: 2
Views: 4212
Reputation: 7670
I created the RemoteLogger library for same situation (need to troubleshoot production only issue in my app).
Provides hooks to append, start, stop, send, and delete log file.
Upvotes: 1
Reputation: 10193
Logcat doesn't require any permission. If you want create your own log, just append log into a text file.
I tried this way myself (require write file permission):
public static void appendLog(String text)
{
File logFile = new File("sdcard/log.file");
if (!logFile.exists())
{
try
{
logFile.createNewFile();
} catch (IOException e)
{
e.printStackTrace();
}
}
try
{
// BufferedWriter for performance, true to set append to file flag
BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
buf.append(text);
buf.newLine();
buf.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
Another choice is log4j for android, and it also require WRITE_EXTERNAL_STORAGE permission
Upvotes: 0