Since Jelly Been I am not able to tell my testers to use alogcat
app to send me logs, because Android now doesn't allow apps to read logs.
Because of this I need to implement my own log-to-file, I'm thinking about something like:
MyLog.d(TAG, "some log");
And as I'm somewhat new to Java's IO performance wise (especially in android perspective), what I'm not sure about is what is the best option to implement this function:
MyLog.d
opens file handle, writes to file, closes handleMyLog.d
opens a static file handle on first invocation and keeps it open during the whole app session, all writes are sent to it as required, flushes follow each write. closes it somewhere on app exit/going-to-bg
Because there are potentially big amounts of logging calls involved, I'm worried that first one might cause to many handle opens/closes and this might degrade performance. While the second one might have some other drawbacks (data losses? anything else?)
Also which is preferrable from the GC perspective? Looks like first one would generate quite some garbage too (new OutputStream on every log call)
So it seems that first option tends to end up quite expensive, while I'm not sure what 'hidden bad things' second one might have :)
Would be grateful for advice from anyone with experience in this area.