0

I would like to log some data of my application activity so as to read it latter on in the system. The data includes strings, floats etc collected when a button is pressed. What is the best way to do this?

Primal Pappachan
  • 25,857
  • 22
  • 67
  • 84

2 Answers2

1

I ended up writing my own function for logging on the device.

public static BufferedWriter out;
    private void createFileOnDevice(Boolean append) throws IOException {
            /*
             * Function to initially create the log file and it also writes the time of creation to file.
             */
            File Root = Environment.getExternalStorageDirectory();
            if(Root.canWrite()){
                 File  LogFile = new File(Root, "Log.txt");
                 FileWriter LogWriter = new FileWriter(LogFile, append);
                 out = new BufferedWriter(LogWriter);
                 Date date = new Date();
                 out.write("Logged at" + String.valueOf(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "\n"));
            }
        }

public void writeToFile(String message){
        try {
            out.write(message+"\n");
        } catch (IOException e) {
            e.printStackTrace();
        }

The related question on SO is here.

Community
  • 1
  • 1
Primal Pappachan
  • 25,857
  • 22
  • 67
  • 84
0

Logcollector is the option for you but you need to install it first on your device.

Again you can save the activity log via adb

Run adb shell logcat > your_log_file.txt from your command prompt.

Tanmay Mandal
  • 39,873
  • 12
  • 51
  • 48
  • Thanks. The app is used for reading WiFi signals and recording strength and so I cannot keep it connected to the system while working. Regarding Logcollector, is there a way to store the log as a file and latter on access it rather than mail/sms? – Primal Pappachan Apr 19 '11 at 09:58
  • Then you have to make your own log collector methods or you can try to change the codes of LogCollector.Another method you can try is to save the logs in a sqllite data database then try to read them later. – Tanmay Mandal Apr 19 '11 at 10:06