/*
Swisscom Safe Connect
Copyright (C) 2014 Swisscom
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.swisscom.safeconnect.utils;
import android.content.Context;
import android.util.Log;
import com.swisscom.safeconnect.BuildConfig;
import java.io.*;
/**
* Created by cianci on 20.05.14.
*/
public class Logger {
public static File saveLogs (Context context){
BufferedReader br;
InputStreamReader isr = null;
File file = new File(context.getExternalFilesDir(null), Config.LOG_FNAME);
FileOutputStream fs = null;
OutputStreamWriter wr = null;
try {
fs = new FileOutputStream(file);
wr = new OutputStreamWriter(fs);
Process logcat = Runtime.getRuntime().exec("logcat -d -v time");
isr = new InputStreamReader(logcat.getInputStream());
br = new BufferedReader(isr);
String line = "";
while ((line = br.readLine()) != null) {
wr.append(line).append("\n");
}
br.close();
isr.close();
wr.close();
fs.close();
} catch (FileNotFoundException e) {
if (BuildConfig.DEBUG) Log.e(Config.TAG, "Error: " + e.getMessage(), e);
return null;
} catch (IOException e) {
if (BuildConfig.DEBUG) Log.e(Config.TAG, "Error: " + e.getMessage(), e);
return null;
}
return file;
}
}