Collect All Log.d From Class And Save It Into Sdcard
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 { private final static String
Solution 1:
You can get all logs with the logcat
command. You can try something like:
publicstaticvoidprintLog(Context context){
Stringfilename= context.getExternalFilesDir(null).getPath() + File.separator + "my_app.log";
Stringcommand="logcat -d *:V";
Log.d(TAG, "command: " + command);
try{
Processprocess= Runtime.getRuntime().exec(command);
BufferedReaderin=newBufferedReader(newInputStreamReader(process.getInputStream()));
Stringline=null;
try{
Filefile=newFile(filename);
file.createNewFile();
FileWriterwriter=newFileWriter(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
Solution 2:
Solution 3:
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
Solution 4:
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();
FileWriterwriter=newFileWriter(file);
while((line = in.readLine()) != null){
if(line.contains("TAG_NAME")){ // Trick :-)
writer.write(line + "\n");
}
}
Post a Comment for "Collect All Log.d From Class And Save It Into Sdcard"