Hey is it possible in Android to collect all Log.d from one class and keep on appending it and save it into SDCard ?
For example :
Class Android {
You can override the Log class and do that yourself. But is it really required for your purposes?
You can get all logs with the logcat
command. You can try something like:
public static void printLog(Context context){
String filename = context.getExternalFilesDir(null).getPath() + File.separator + "my_app.log";
String command = "logcat -d *:V";
Log.d(TAG, "command: " + command);
try{
Process process = Runtime.getRuntime().exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
try{
File file = new File(filename);
file.createNewFile();
FileWriter writer = new FileWriter(file);
while((line = in.readLine()) != null){
writer.write(line + "\n");
}
writer.flush();
writer.close();
}
catch(IOException e){
e.printStackTrace();
}
}
catch(IOException e){
e.printStackTrace();
}
}
You can get more information about logcat
here: http://developer.android.com/tools/help/logcat.html
no, Log.* methods write to the console, however you can use Logger http://developer.android.com/reference/java/util/logging/Logger.html and a FileHandler
If you want to add logs with tag name and
logcat -s <Tagname>
Is not working for you then you can do this trick
//... Brtle 's code..(accepted one )
file.createNewFile();
FileWriter writer = new FileWriter(file);
while((line = in.readLine()) != null){
if(line.contains("TAG_NAME")){ // Trick :-)
writer.write(line + "\n");
}
}